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 warning: "Critical dependency: the request of a dependency is an expression" #4959
Comments
Hi! Can you make a repo that reproduces the problem? That would be really helpful! |
Here's a sample repo demonstrating the problem: https://github.com/philcockfield/prettier-sample WARNING in ./node_modules/prettier/standalone.js
7397:15-64 Critical dependency: the request of a dependency is an expression
@ ./node_modules/prettier/standalone.js
@ ./lib/common/prettier.js
@ ./lib/common/index.js
@ ./lib/test/storybook.js
@ ./lib/components/Foo.stories.js
@ ./lib stories.js$
@ ./.storybook/config.js
@ multi ./node_modules/@storybook/react/dist/server/config/polyfills.js ./node_modules/@storybook/react/dist/server/config/globals.js (webpack)-hot-middleware/client.js?reload=true ./.storybook/config.js
Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 569 kB 1
7b056e65e12fac1b83ba.hot-update.json 44 bytes [emitted]
[0] ./node_modules/html-webpack-plugin/lib/loader.js!./node_modules/@storybook/react/dist/server/index.html.ejs 1.7 kB {1}
[1] ./node_modules/lodash/lodash.js 540 kB {1}
[2] (webpack)/buildin/global.js 509 bytes {1}
[3] (webpack)/buildin/module.js 517 bytes {1}
Child html-webpack-plugin for "iframe.html":
Asset Size Chunks Chunk Names
iframe.html 569 kB 1
63d0aee88fe26bae2acc.hot-update.json 44 bytes [emitted]
[0] ./node_modules/html-webpack-plugin/lib/loader.js!./node_modules/@storybook/react/dist/server/iframe.html.ejs 1.16 kB {1}
[1] ./node_modules/lodash/lodash.js 540 kB {1}
[2] (webpack)/buildin/global.js 509 bytes {1}
[3] (webpack)/buildin/module.js 517 bytes {1} |
Awesome! Is there any chance you could make the example smaller? For example, get rid of Storybook and Typescript? I think that would increase your chances of this getting fixed. |
Here are details on what that error is and means within Webpack: And it looks like a work around to this, prior to it being fixed within Prettier itself, is to use ContextReplacementPlugin as per this comment It looks like something in Hopefully that gives something more to go on. |
Might be this line:
|
Boom! Looks like that would do it!!
|
@philcockfield That thread says nothing about how to actually implement a workaround, just a vague comment about maybe using ContextReplacementPlugin. I'm just putting it out there so people don't waste their time skimming the entire thread |
@nickarnold - cool, I haven't figured out how to use that
|
Confirmed that if the following two lines in the build
Location in source code and
Location in source code |
It's a warning, isn't it? Are you sure that line 14793 causes a warning? That sounds strange to me. That line is basically just building a string containing the word "require" – surely that has to be allowed by webpack? |
1 similar comment
This comment has been minimized.
This comment has been minimized.
Damn, my bad on both accounts @lydell. Just re-tested and it is just line
|
I've just figured out I can suppress this with this webpack plugin, so I'll do that for now. Mentioning here if anyone else it trying to do the same. config.plugins.push(
new FilterWarningsPlugin({
exclude: /Critical dependency: the request of a dependency is an expression/,
}),
); As @lydell points out, it's a "warning" from Webpack, not an error, but man Webpack really does scream blue-murder about this in the console, which makes it hard to disambiguate from actual errors when developing. |
Note that that message has bundle size implications. |
It doesn't make sense to have this line of code Line 47 in 0c7c1bf
process.cwd ). Webpack warns because that statement is implicitly asking it to compile all the code that could possibly be imported for any value of process.cwd() and opts.parser . Seeing as that's impossible I assume it gives up and lets it crash.
If you were compiling some node project that used prettier, and you wanted to use the functionality to specify a custom parser, you would probably want to pass it as a node API option, not as a CLI option. Perhaps it makes sense for the main entry point not to import the code that parses the CLI |
There is an warning that is cause by one of the dependencies, the upstream bug is prettier/prettier#4959
There is an warning that is cause by one of the dependencies, the upstream bug is prettier/prettier#4959
This happens because Webpack doesn't actually use require() as a function but a RegEx, so the Node usage of require() as a file reader doesn't work in Webpack. This should be taken out for the stand alone version. |
PRs welcome |
Proposal:
|
If you’re currently experiencing this warning, can you try installing |
Good job and thanks for the fix! |
Ah, good point @ikatyang. |
When is this slated for release? |
Probably sometime in January. |
Environments:
Steps to reproduce:
npm install --save --save-exact prettier
in some component
Expected behavior:
No compilation warnings
Actual behavior:
WARNING in ./node_modules/prettier/standalone.js
7397:15-64 Critical dependency: the request of a dependency is an expression
(everything seems to work well, the issue is just the compilation warning)
The text was updated successfully, but these errors were encountered: