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

webpack resolves symlinked child node_modules due to unused nodeModulesDir in template #961

Open
jbockle opened this issue Nov 2, 2018 · 4 comments

Comments

@jbockle
Copy link
Contributor

jbockle commented Nov 2, 2018

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 webpack/webpack#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?

    const nodeModulesDir = path.resolve(__dirname, 'node_modules');
    has unused variable that should be used in resolve.modules

@Alexander-Taran
Copy link
Contributor

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

@EisenbergEffect
Copy link
Contributor

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

@3cp
Copy link
Member

3cp commented Feb 5, 2019

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

@rockResolve
Copy link

rockResolve commented Mar 18, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants