Skip to content
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

Conversation

douglasduteil
Copy link
Contributor

@douglasduteil douglasduteil commented May 26, 2017

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

/packages/my-ng-app
├── dist
├── e2e
├── node_modules
│   ├── @angular
│   │   ├── animations
│   │   ├── cli
│   │   │   ├── ...
│   │   │   ├── node_modules
│   │   │   │   ├── ...
│   │   │   │   ├── css-loader
│   │   │   │   ├── extract-text-webpack-plugin
│   │   │   │   ├── file-loader
│   │   │   │   ├── html-webpack-plugin
│   │   │   │   ├── istanbul-instrumenter-loader
│   │   │   │   ├── karma-sourcemap-loader
│   │   │   │   ├── less-loader
│   │   │   │   ├── @ngtools
│   │   │   │   ├── sass-loader
│   │   │   │   ├── script-loader
│   │   │   │   ├── source-map-loader
│   │   │   │   ├── style-loader
│   │   │   │   ├── stylus-loader
│   │   │   │   ├── supports-color
│   │   │   │   ├── url-loader
│   │   │   │   ├── webpack
│   │   │   │   └── ...

Copy link
Member

@clydin clydin left a 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),
Copy link
Member

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
Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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.

@douglasduteil douglasduteil force-pushed the fix-angular-cli-resolve-in-all-available-node-modules branch from 30fb86c to 8fec989 Compare May 26, 2017 12:11
@douglasduteil
Copy link
Contributor Author

Thanks for you feedback @clydin

@douglasduteil douglasduteil force-pushed the fix-angular-cli-resolve-in-all-available-node-modules branch from f4b8524 to b972943 Compare May 26, 2017 14:12
@@ -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']
Copy link
Member

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.

Copy link
Member

@clydin clydin left a 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[];
}
Copy link
Member

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.

@douglasduteil douglasduteil force-pushed the fix-angular-cli-resolve-in-all-available-node-modules branch from b972943 to 8fcd402 Compare May 27, 2017 08:49
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.
@douglasduteil douglasduteil force-pushed the fix-angular-cli-resolve-in-all-available-node-modules branch from 8fcd402 to 93e584b Compare May 27, 2017 17:04
Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@hansl hansl merged commit be7a716 into angular:master May 31, 2017
@douglasduteil douglasduteil deleted the fix-angular-cli-resolve-in-all-available-node-modules branch May 31, 2017 21:09
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants