-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(@angular/cli): resolve in all available node_modules #6475
fix(@angular/cli): resolve in all available node_modules #6475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested changes essentially revert (with modifications) PR #3422.
@@ -67,10 +68,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) { | |||
devtool: buildOptions.sourcemaps ? 'source-map' : false, | |||
resolve: { | |||
extensions: ['.ts', '.js'], | |||
modules: ['node_modules', nodeModules], | |||
modules: [appRoot].concat(nodeModules), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is correct. Please revert.
}, | ||
resolveLoader: { | ||
modules: [nodeModules] | ||
modules: nodeModules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
resolveLoader: {
modules: [nodeModules, 'node_modules']
}, | ||
resolveLoader: { | ||
modules: [nodeModules] | ||
modules: nodeModules | ||
}, | ||
context: projectRoot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to:
context: __dirname,
@@ -23,7 +23,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) { | |||
const { projectRoot, buildOptions, appConfig } = wco; | |||
|
|||
const appRoot = path.resolve(projectRoot, appConfig.root); | |||
const nodeModules = path.resolve(projectRoot, 'node_modules'); | |||
const projectRootNodeModules = path.resolve(projectRoot, 'node_modules'); | |||
const nodeModules = module.paths.slice(0, module.paths.indexOf(projectRootNodeModules) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary (see comments below) and uses an undocumented API.
30fb86c
to
8fec989
Compare
Thanks for you feedback @clydin |
f4b8524
to
b972943
Compare
@@ -67,12 +67,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) { | |||
devtool: buildOptions.sourcemaps ? 'source-map' : false, | |||
resolve: { | |||
extensions: ['.ts', '.js'], | |||
modules: ['node_modules', nodeModules], | |||
modules: [nodeModules, 'node_modules'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this one unchanged. Standard node module resolution needs to take precedence to avoid incorrect transitive package versions from being resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could, please remove the test changes (they're not relevant to the actual problem being solved) and add a test case covering the use case you described above (loaders not in project root node modules).
|
||
interface NodeModule { | ||
paths: string[]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this file. This isn't needed anymore.
b972943
to
8fcd402
Compare
When @angular/cli dependencies (like @ngtool/webpack for example) are installed in its node_modules (as node_modules/@angular/cli/node_modules for example) webpack isn't seeing them.
8fcd402
to
93e584b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
When @angular/cli dependencies (like @ngtool/webpack for example) are installed in its node_modules (as node_modules/@angular/cli/node_modules for example) webpack isn't seeing them.
Actually I experienced it when trying to use lerna with ng-cli. As Lerna try to be smart about how the node_modules are shared between different packages, it's installing the
@angular/cli
dependencies in the@angular/cli/node_modules