Cannot find module 'webpack'
JoostK opened this issue · 3 comments
Several packages are failing during ng build
with the following stacktrace:
An unhandled exception occurred: Cannot find module 'webpack'
Require stack:
- /home/circleci/repo/ng2-translate-ngcc/node_modules/webpack-dev-server/lib/Server.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular-devkit/build-angular/node_modules/@angular-devkit/build-webpack/src/webpack-dev-server/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular-devkit/build-angular/node_modules/@angular-devkit/build-webpack/src/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular-devkit/build-angular/src/browser/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/models/architect-command.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/commands/build-impl.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/utilities/json-schema.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/models/command-runner.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/lib/cli/index.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/lib/init.js
- /home/circleci/repo/ng2-translate-ngcc/node_modules/@angular/cli/bin/ng
See "/tmp/ng-89lOqi/angular-errors.log" for further details.
During this job it occurred 7 times.
This does not seem to be deterministic, although I can reproduce locally. Looking at the NPM dependency graph, the following is observed:
webpack-dev-server
has a peer dep onwebpack
@angular-devkit/build-angular
has a dep onwebpack
andwebpack-dev-server
Those appear the only relevant dependencies that require webpack
/webpack-dev-server
.
Sometimes, the deps of @angular-devkit/build-angular
are installed as follows:
webpack
goes intonode_modules/@angular-devkit/build-angular/node_modules/webpack
webpack-dev-server
goes intonode_modules/webpack-dev-server
This is the cause of the problem, as webpack
is no longer in scope of the webpack-dev-server
installation.
How this occurs is unclear to me. It feels like an inconsistency in how NPM hoists packages, which smells like a bug to me.
@alan-agius4 Since this occurs in very minimal CLI projects, are you aware of any issues with the CLI when NPM is being used?
@JoostK, I’ll have a look tomorrow morning.
What I am thinking is that it’s related to the fact that the CLI snapshots have a different webpack version than the one defined in the lock file. Which is causing some hosting issues.
Not the first time that we encountered issues with hoisting with npm.
@mgechev, any reason why not use renovate to update the commit sha? Is it because it will use a lot of CI time. (maybe we limit the updates?)
The reason being is like this failing builds will be hard to reproduce.
I took a look at this and I should have a fix, though to generate the lock files it's taking hours. Which is also worrying me a bit as I am not sure how renovate will behave with so many co-current updates to package.json