Can't resolve 'fs' when bundle with webpack
Do you want to request a feature or report a bug? Bug
What is the current behavior?
Webpack finish bundle without errors with css-loader 0.26.4.
After update to 0.27.0 webpacking finished with error:
ERROR in ./~/convert-source-map/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Projects\project_name\node_modules\convert-source-map'
@ ./~/convert-source-map/index.js 2:9-22
@ ./~/css-loader/lib/css-base.js
If the current behavior is a bug, please provide the steps to reproduce.
- Update css-loader from
0.26.4to0.27.0version - Run webpack to build
What is the expected behavior? Works without error
Please mention other relevant information such as your webpack version, Node.js version and Operating System. Windows 8.1 Node.js 7.7.2 Webpack 2.2.1
same here
same here
Same for me, had to rollback that update
same here
Adding
node: {
fs: 'empty'
}
to webpack config file and the error is gone. Not sure how it works, It seems like webpack did some thing with fs module in web target.
add the following to your Webpack config:
node: {
fs: "empty"
}
The issue has been acknowledged and we are in process of figuring out a good fix. No need for "me too"s. Please add a thumbs up on the original issue if you want to do that. 👍
Did you can to unpublish this version? It will keep calm to all of us
@PredokMiF You don't unpublish anything, ever.
The workaround is sufficient and the bug is actually in webpack, related to fs in the web target.
WORKAROUND thanks to @hdnha11 / @mehdivk
node: {
fs: 'empty'
}
If using this workaround isn't viable, version lock to the previous minor version.
@bebraw With your fix of this issue, I have a Uncaught ReferenceError: Buffer is not defined in the lib/convert-source-map.js file, in the browser.
@fklingler I have a proposed fix for that at https://github.com/webpack-contrib/css-loader/pull/453 . Still waiting for some approvals before I can push it. Feel free to give that a go and let me know how it goes.
I came across the same error. I am starting off with JS (with vuejs) and I would like to understand what this does?
I got this error when using the "fetch" library from npm. At first I got the same error but with other packages (net and dns). My first thought was that those are missing dependencies. After running npm install net and npm install dns, those errors were replaced with dgram and fs. The latter one prompted me to hit Google and landed on this issue.
I now added two sections in my webpack config for both fs and dgram, and now the errors are gone.
But I don't know what this entails. Will my compiled code still work? Even if these sections are configured as being empty? What does it actually do?
Also, is this the right place to ask this? Or should it be rather targeted at vuejs?
nb: I would like to give a bit more insight about my running environment but as I'm still getting my feet wet, I don't know which commands are the best to represent a snapshot of my dev-environment. If you need some additional output, let me know which commands to run.
@exhuma See the related page on documentation. That describes the default behavior. You can also find possible overrides there. I hope this helps.
Also, is this the right place to ask this? Or should it be rather targeted at vuejs?
Stack Overflow might be better for this type of questions.
just wanted to add that I fixed this by the answer in https://github.com/josephsavona/valuable/issues/9 about setting target: 'node'
This explains more: http://jlongster.com/Backend-Apps-with-Webpack--Part-I
The target: 'node' option tells webpack not to touch any built-in modules like fs or path.
Hi - when I did
target: 'node',
the error went away. Then I got
global not defined,
so I fixed it with
'global': {}, in webpack.definePlugin({...})
Then I got a GetEnv error saying SERVER_HOST not defined... but it is... so there's a slew of errors that I'm swimming in - I hope someone can take a look at my boilerplate and give me hand? Thank you!
I fixed the problem by changing webpack.config.js:
... var config = Encore.getWebpackConfig(); config.node = { fs: 'empty' }; module.exports = config;
and: yarn add --dev file system
Someone please fix this issue. Non of the mentioned answer could fix it for me
@samayo I'm not sure what I got could help you.
I fix this error by installing node-sass into devDenpendency, if I install node-sass into denpendency, I will get this error, I'm not sure you use node-sass or not, you can check some packages in denpendency and devDenpendency
How should I go about solving this issue when importing an npm module that uses Webpack (i.e., when importing an npm module that imports a package that yields this problem)?
To add some clarity: say I've create two npm modules, both using Webpack. Let's call them module A and module B.
Module A imports require, which yields this error. Thus, in webpack.config.js of module A, I add:
node: {
console: false,
fs: 'empty',
net: 'empty',
tls: 'empty'
}
Module B then imports module A. However, even though I've added the above code in module A, the error still comes up when I try to build module B.
Does anyone know how to solve this problem without adding the above code to module B as well (i.e., modifying only module A)?
Same problem - why is this issue closed? Should I 👍 a different issue?