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.

Webpack Error: Can't resolve 'async/forEach'

See original GitHub issue

my 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:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
nikita-malyschkin-workcommented, May 25, 2018

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.

resolve: {
    modules: [path.resolve(__dirname, "node_modules"), "node_modules"]
}
2reactions
hhaselicommented, Oct 15, 2020

This worked for me:

npm uninstall async
npm install -g async
npm link async
Read more comments on GitHub >

github_iconTop 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 >

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