question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V2 Can't resolve 'fs' in webpack-dev-server/client

See original GitHub issue

There is an error when I use webpack-dev-server; webpack: 2.2.0-rc.1 webpack-dev-server: 2.2.0-rc.0 node: 6.6.0

ERROR in ./~/debug/src/node.js
Module not found: Error: Can't resolve 'net' in '/Users/gaopeng/work/ykpm/node_modules/debug/src'
 @ ./~/debug/src/node.js 186:16-30
 @ ./~/debug/src/index.js
 @ ./~/sockjs-client/lib/main.js
 @ ./~/sockjs-client/lib/entry.js
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://local.youku.com:3333/
 @ multi js/lib

webpackConfig

{
  target: 'web',
  context: '/Users/gaopeng/work/ykpm',
  entry:  { 
     'js/play/live': [
         'webpack-dev-server/client?http://local.youku.com:3333/',
         'webpack/hot/dev-server',
         'js/play/live.js'
    ]
  },
  output: { 
     path: '/',
     publicPath: '/',
     filename: '[name].js',
     pathinfo: false,
     chunkFilename: '[name].js',
  },
  module: {												
      rules: [{
          test: /.js?$/,
	 exclude: /node_modules/,
	 use: [
	     { loader: 'babel-loader' }
	 ]
      }]									
  },
  resolve: { 
     modules: [ '/Users/gaopeng/work/ykpm/src', 'node_modules' ],
     extensions: [ '.js', '.json' ]
  },
  plugins:[new HotModuleReplacementPlugin()]
}

devServerConfig

{
 contentBase: './static/',
  https: false,
  host: 'local.yk.com',
  port: 3333,
  hot: true,
  inline: true,
  stats: { colors: true }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
SpaceK33zcommented, Jan 17, 2017

I could reproduce your issue. It’s caused by using resolve.mainFields in your webpack config. If you remove that, it works. You can add custom fields to it, but be sure to add at least ["browser", "module", "main"].

0reactions
beliefgpcommented, Jan 4, 2017

here is template nodejs version v6.6.0 run npm run test output error

ERROR in ./~/debug/src/node.js
Module not found: Error: Can't resolve 'fs' in '/Users/gaopeng/work/webpack-dev-ser-test/node_modules/debug/src'
 @ ./~/debug/src/node.js 174:15-28
 @ ./~/debug/src/index.js
 @ ./~/sockjs-client/lib/main.js
 @ ./~/sockjs-client/lib/entry.js
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:8080
 @ multi js/play/live

ERROR in ./~/debug/src/node.js
Module not found: Error: Can't resolve 'net' in '/Users/gaopeng/work/webpack-dev-ser-test/node_modules/debug/src'
 @ ./~/debug/src/node.js 181:16-30
 @ ./~/debug/src/index.js
 @ ./~/sockjs-client/lib/main.js
 @ ./~/sockjs-client/lib/entry.js
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:8080
 @ multi js/play/live

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'fs' in - Stack Overflow
I found a possible solution, that you have to put some configuration in one of the node_modules. But I think that is not...
Read more >
Module not found: Can't resolve 'fs' error [Solved] | bobbyhadz
The error "Module not found: Error: Can't resolve 'fs'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
can't resolve 'fs' in webpack | The AI Search Engine You Control
Another way is to let Webpack ignore fs module by adding "node": { "fs": "empty" } in the webpack configuration. Open side panel....
Read more >
Resolve | webpack
For example, when calling import 'lodash' in ES2015, the resolve options can change where webpack goes to look for 'lodash' (see modules )....
Read more >
[Node] Simple Next.js app, can't resolve 'fs' - Agents
NextJS v12+ does not support Webpack v4, which is where I think the problems with 'fs' and other packages were coming from. Either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found