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 warning on a require.resolve #1099

Closed
webpack-bot opened this issue Apr 11, 2017 · 6 comments
Closed

Critical dependency warning on a require.resolve #1099

webpack-bot opened this issue Apr 11, 2017 · 6 comments
Assignees

Comments

@webpack-bot
Copy link

webpack-bot commented Apr 11, 2017

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Critical dependency warning on require.resolve call.

If the current behavior is a bug, please provide the steps to reproduce.

Create a file with following contents and process it with default webpack config:

let resolvedPath = require.resolve(`${somepath}`);

What is the expected behavior?

No warnings expected due to this is not a require statement and no external modules are loaded.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

macOS 10.12.4 (16E195)
nodeJS v7.7.2
webpack v2.3.3


This issue was moved from webpack/webpack#4681 by @sokra. Orginal issue was by @dkfiresky.

Document behavior for dynamic expressions.

webpack is a static bundler and requires statically analysable expressions.

@skipjack
Copy link
Collaborator

skipjack commented Apr 11, 2017

This seems related to #1083. If I understand correctly, webpack can't import(...) or require a pure variable e.g. import(varName) because there's no way to determine what group of files are being referred to. However, something like:

import('./directory/${varName}.css')

gives webpack enough information to go bundle all css files from ./directory and make them accessible as require-able modules when the variable is actually defined. @webpack/documentation-team is this correct?

@bebraw
Copy link
Contributor

bebraw commented Apr 11, 2017

My understanding is that import('./directory/${varName}.css') sets up a require.context internally. If you had import(varName), how could you tell statically where to point in the file system?

@ghost
Copy link

ghost commented Apr 11, 2017

Can you please clarify why webpack thinks that require.resolve and require are the same?
As if I used the require(varName) instead of require.resolve(varName)?

@simon04
Copy link
Collaborator

simon04 commented Apr 19, 2017

With #1110 merged, is there anything left to be done?

@skipjack
Copy link
Collaborator

@dkfiresky based on the old docs, it seems require.resolve does not behave exactly like require and instead returns the id for that module. However, after a quick search, I couldn't find anything in the new docs analogous to the page I just linked to. I'm not too familiar with require.resolve in webpack so we'd have to check with the rest of @webpack/documentation-team, but it seems maybe we should add a similar page in the new /content/api section?

I'd be happy to try to port this page over if someone gives me some pointers on what is and isn't still relevant.

@ghost
Copy link

ghost commented Apr 27, 2017

@skipjack thanks for clarification. I thought that require.resolve in webpack worked the same way as in nodejs.

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

No branches or pull requests

4 participants