qdouble / angular-webpack-starter

A complete Angular 6 and Webpack 4 starter seed with minimal and full featured branches. Full featured branch includes: Material Design 2 (Bootstrap 4 branch available as well), @ngrx, HMR, DLLs and optional use of Universal for server-side rendering - Supports AOT (offline) compilation, sync and lazy loading. Karma/Protractor for e2e/unit tests.
MIT License
883 stars 181 forks source link

Getting "Cannot find module 'zone.js/dist/zone-node'" when deploying on production server #330

Open tonihuang opened 6 years ago

tonihuang commented 6 years ago

Hi there,

Thank you for the great starter template! I have been using it to create application and when i'm about to deploy to production server i get "Cannot find module 'zone.js/dist/zone-node'. The steps that i did was:

  1. yarn universal
  2. copy dist/ and dll/ folder to server
  3. Runnode dist/server.js The fuill stacktrace is as below Error: Cannot find module 'zone.js/dist/zone-node' at Function.Module._resolveFilename (module.js:476:15) at Function.Module._load (module.js:424:25) at Module.require (module.js:504:17) at require (internal/module.js:20:19) at Object.zone.js/dist/zone-node (/var/.../myapp/dist/server.js:9138:18) at webpack_require (/var/.../myapp/dist/server.js:20:30) at Object. (/var/.../myapp/dist/server.js:8647:130) at Object../src/server.ts (/var/.../myapp/dist/server.js:8711:30) at webpack_require (/var/.../myapp/dist/server.js:20:30) at /var/.../myapp/dist/server.js:63:18

I can run it on the generated server.js in local but not on server. Any help will be appreciated. Thanks!

SamuelThomas78 commented 6 years ago

Hi, I have same problem did you find a solution ?

tonihuang commented 6 years ago

Hi Samuel,

I ended up performing yarn install on server to have the package installed on server.

nagarajukmenlo commented 5 years ago

Hi, When we run node dist/server.js I am getting following error:

Error: Invalid provider for undefined. useClass cannot be undefined. Usually it happens when:

  1. There's a circular dependency (might be caused by using index.ts (barrel) files).
  2. Class was used before it was declared. Use forwardRef in this case. at syntaxError (C:\Users\nagaraajuk\Desktop\New folder\dist\node_modules\@angular\compiler\bundles\compiler.umd.js:287:21)

Node Version: 9.11.0 Webpack version: 4.0.0 NPM version: 5.6.0

Please help us to resolve the above issue.

Thanks.

nagarajukmenlo commented 5 years ago

Hi All,

I got a fix for the above-mentioned issue.

I have added below lines in webpak.config.ts

"module": { "rules": [ { "enforce": "pre", "test": /.js$/, "loader": "source-map-loader", "exclude": [ // instead of /\/node_modules\// path.join(process.cwd(), 'node_modules') ] },

abelokon0711 commented 5 years ago

@nagarajukmenlo unfortunately your solution did not help. we get still the same error

ohabash commented 5 years ago

I have the same problem. The problem started when i was trying to fix another problem . My universal app kept failing during build but doing the following in webpack.server.config.js allowed the app to build. But cause the same problem you guys described above.

const nodeExternals = require('webpack-node-externals');

module.exports = {
...
   externals: [nodeExternals()],
...
}

Did you guys find a solution? are you still working on it?