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

Critical dependency: the request of a dependency is an expression #2115

Closed
rolele opened this issue Jun 17, 2017 · 8 comments
Closed

Critical dependency: the request of a dependency is an expression #2115

rolele opened this issue Jun 17, 2017 · 8 comments

Comments

@rolele
Copy link

rolele commented Jun 17, 2017

this code:
https://github.com/mishoo/UglifyJS2/blob/master/tools/node.js#L18

will trigger a warning in webpack:

../~/uglify-js/tools/node.js
24:11-32 Critical dependency: the request of a dependency is an expression
    at RequireResolveContextDependency.getWarnings (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js:27:4)
    at Compilation.reportDependencyErrorsAndWarnings (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:672:24)
    at Compilation.finish (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:535:9)
    at /Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compiler.js:491:16
    at /Users/others/wishlist/client/wishlist-client/node_modules/webpack/node_modules/tapable/lib/Tapable.js:225:11
    at _addModuleChain (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:481:11)
    at processModuleDependencies.err (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:452:13)
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)

The point here is that from that point webpack is unable to optimize the import and you endup with the whole js in your final bundle.

@kzc
Copy link
Contributor

kzc commented Jun 17, 2017

The point here is that from that point webpack is unable to optimize the import and you endup with the whole js in your final bundle.

That's by design.

@rolele
Copy link
Author

rolele commented Jun 17, 2017

I see that you import all the libs at that point.
Now what about the warning?

@rolele
Copy link
Author

rolele commented Jun 17, 2017

instead of the map function, you could just require each js and the warning will be gone.

@alexlamsl
Copy link
Collaborator

If you need to parse & embed uglify-js, consider using the version generated by --self

@rolele
Copy link
Author

rolele commented Jun 17, 2017

I need to see this warnig go away. that is all.
Instead of using the require function in your code passing a variable, you could simply:

    require.resolve("../lib/utils.js"),
    require.resolve("../lib/ast.js"),
   ...

@alexlamsl
Copy link
Collaborator

@rolele thanks for the clarification, though I still don't see the point. We can't keep making cosmetic changes whenever a third party tool decides to emit a new warning.

@rolele
Copy link
Author

rolele commented Jun 17, 2017

I agree @alexlamsl.
Now we are talking about webpack which is one of the mainstream tool to build js today.
Look at what the core-team of webpack is saying about this issue here:
webpack/webpack#196
This is a bad practice for the right reasons and can be easily solved in most cases (your case included)

@stevenschlansker
Copy link

I also ran into this problem. As highlighted above, the fix is simple. Please see #3432

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

Successfully merging a pull request may close this issue.

4 participants