Webpack Error: Can't resolve 'async/forEach'
See original GitHub issuemy environment:
- winston 3.0.0-rc5
- node 6.7.0
- OS Linux
- ES6/7 with webpack+babel
What is the problem?
When using webpack to bundle my server code I get an error while bundling when using winston:
ERROR in ../node_modules/winston/lib/winston/exception-handler.js
Module not found: Error: Can't resolve 'async/forEach' in '~/myProject/node_modules/winston/lib/winston'
resolve 'async/forEach' in '~/myProject/node_modules/winston/lib/winston'
Parsed request is a module
using description file: ~/myProject/node_modules/winston/package.json (relative path: ./lib/winston)
after using description file: ~/myProject/node_modules/winston/package.json (relative path: ./lib/winston)
resolve as module
looking for modules in ~/myProject/node_modules
using description file: ~/myProject/package.json (relative path: ./node_modules)
after using description file: ~/myProject/package.json (relative path: ./node_modules)
using description file: ~/myProject/node_modules/async/package.json (relative path: ./forEach)
no extension
~/myProject/node_modules/async/forEach doesn't exist
.js
~/myProject/node_modules/async/forEach.js doesn't exist
.json
~/myProject/node_modules/async/forEach.json doesn't exist
as directory
~/myProject/node_modules/async/forEach doesn't exist
my code:
import winston from "winston";
[...]
opening a node console and using CommonJS require
does not lead to any error,
so I suppose it’s a combination of winston and webpack.
my webpack config looks like this:
const ServerConfig = {
context: distPath,
entry: ["babel-polyfill", path.resolve(srcPath, "src", "server")],
output: {
path: distPath,
filename: "server.bundle.js"
},
profile: true,
stats: outputOptions,
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ["happypack/loader?id=js"]
}
]
},
target: "node",
plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false }),
new CopyWebpackPlugin([
{
context: srcPath,
from: "config",
to: "config"
}
]),
new HappyPack({
id: "js",
loaders: [
{
loader: "babel-loader",
options: {
cacheDirectory: true
}
}
]
}),
/**
* The settings below fix warnings due to require path handling. Switching context to packages
* base folder solves some warnings. Colors package dynamically requires themes, which we'll
* assign the default located at the packages themes folder.
*/
new webpack.ContextReplacementPlugin(/colors[\/\\]lib$/, "../themes/generic-logging.js")
],
resolve: {
modules: [path.resolve(__dirname, "node_modules")]
},
externals: nodeModules
};
What do you expect to happen instead?
Well …
Other information
It looks like winston is trying to require something, that is not part of the async package.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Adding await/async in typescript throws can't resolve 'imports'
The error is not related to async / await but to the import of fetch that you specified in ProvidePlugin . It's no...
Read more >async-foreach - npm
Start using async-foreach in your project by running `npm i async-foreach`. There are 92 other projects in the npm registry using ...
Read more >JavaScript: async/await with forEach() | by Sebastien Chopin
We can solve this by creating our own asyncForEach() method: async function asyncForEach(array, callback) { for (let index = 0; index < array.length; ......
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 >Migrating from v2 to v3 - Gatsby
A common error is process is not defined . webpack 4 polyfilled process automatically in the browser, but with v5 it's not the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
removing the
resolve
statement in the webpack config solved my issue, thanks! 👍I still wonder why this wasn’t an issue with all my other modules.
PS. Adding
"node_modules"
to the array fixed the problem as well.This worked for me: