cli icon indicating copy to clipboard operation
cli copied to clipboard

webpack resolves symlinked child node_modules due to unused nodeModulesDir in template

Open jbockle opened this issue 7 years ago • 4 comments

I'm submitting a bug report

  • Library Version: current (I'm using 0.34.0)

Please tell us about your environment:

  • Operating System: Windows 10

  • Node Version: 10.4

  • NPM Version: 6.4.1

  • Browser: all

  • Language: TypeScript

  • Loader/bundler: Webpack

Current behavior: See https://github.com/webpack/webpack/issues/8322 child node_modules dependencies are being bundled

  • What is the expected behavior? only node_modules root should be resolved

  • What is the motivation / use case for changing the behavior? https://github.com/aurelia/cli/blob/cb78d99a79d721e841fa4ddf4a648314edd1db97/lib/resources/content/webpack.config.template.js#L20 has unused variable that should be used in resolve.modules

jbockle avatar Nov 02 '18 16:11 jbockle

Would you like to provide a pull request for it @jbockle ?

Alexander-Taran avatar Nov 13 '18 13:11 Alexander-Taran

We're going to need to revert the above fix due to a regression it caused.

EisenbergEffect avatar Feb 05 '19 00:02 EisenbergEffect

Sorry @jbockle we need to find other way to support this. It's too risky to change webpack's default module resolution.

3cp avatar Feb 05 '19 00:02 3cp

In addition to #1037, the above fix forces all modules to use child modules from the node_modules root regardless of versioning. No multiple versions warnings are given.

If you really want to use a single version (i.e. you know better than the package insisting on a different version), you can use webpack's resolve.alias. https://www.npmjs.com/package/duplicate-package-checker-webpack-plugin#resolving-duplicate-packages-in-your-bundle

In my case, once the fix was reverted I started getting warnings that I had multiple versions of jquery: one from root & one in a child node_modules.

I checked via --analyze, but I was only getting one version without any alias code. It appears a separate aliasing fix of adding a ProviderPlugin entry, was additionally fixing the module resolution to just the root version.

Workaround jquery example:

webpack.config.js 
    plugins
            new ProvidePlugin({
                $: "jquery",
                jQuery: "jquery",
               "window.jQuery": "jquery"
                //As well as aliasing multiple nicknames,
                // this is also results in only the node_modules root version being used
             }

By default, module resolution path is current folder (./**) and node_modules. So the above code results in only the node_modules root jquery version being included. Once the fix was reverted, this continued but webpack showed a multiple versions warning.

rockResolve avatar Mar 18 '19 21:03 rockResolve