shaketbaby / directory-named-webpack-plugin

A Webpack plugin that treats a file with the name of directory as the index file
MIT License
182 stars 17 forks source link

Webpack 3 can't resolve 'fs' and 'net' #17

Closed zorahrel closed 7 years ago

zorahrel commented 7 years ago

I updated to Webpack 3, if I add the plugin in resolve's plugins list I have this error in console.


Module not found: Error: Can't resolve 'fs' in '/MY-PROJ-DIR/node_modules/debug/src'
 @ ./node_modules/debug/src/node.js 184:15-28
 @ ./node_modules/debug/src/index.js
 @ ./node_modules/sockjs-client/lib/main.js
 @ ./node_modules/sockjs-client/lib/entry.js
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:8080
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server react-hot-loader/patch webpack/hot/only-dev-server ./src/index.js

ERROR in ./node_modules/debug/src/node.js
Module not found: Error: Can't resolve 'net' in '/MY-PROJ-DIR/node_modules/debug/src'
 @ ./node_modules/debug/src/node.js 191:16-30
 @ ./node_modules/debug/src/index.js
 @ ./node_modules/sockjs-client/lib/main.js
 @ ./node_modules/sockjs-client/lib/entry.js
 @ (webpack)-dev-server/client/socket.js
 @ (webpack)-dev-server/client?http://localhost:8080
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server react-hot-loader/patch webpack/hot/only-dev-server ./src/index.js```
shaketbaby commented 7 years ago

I haven't tested with Webpack 3 yet, will look into it. fs and net look like Node.js built in modules, are you importing them in your client codes? Are you able to provide some more info? Project structure, webpack config file, etc if possible. Thanks!

shaketbaby commented 7 years ago

Looks like sockjs-client will require module debug if it not PROD env which tries to detect and ends up importing the file for Node.js instead of browser. Can you try to specify honorPackage option to look for browser first?

new DirectoryNamedWebpackPlugin({
  honorPackage: ["browser", "main"],
  // any other options needed
})

Please let me know if this works.

shaketbaby commented 7 years ago

Can you please let me know if this plugin works for you now? Thanks!

shaketbaby commented 7 years ago

I am closing this now as I have upgraded WP to version 3 for our project and the plugin works fine. Can't do much without further info.

tomasfrancisco commented 7 years ago

Hi @shaketbaby, I was having the same problem here. The honorPackage has resolved the issue.