Error: Cannot find module ‘webpack/lib/removeAndDo’ when building a project

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

Running my build returns an error:

“build”: “node ./node_modules/webpack/bin/webpack.js -p”,

npm run-script build

Error: Cannot find module ‘webpack/lib/removeAndDo’
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Author: Fantashit

6 thoughts on “Error: Cannot find module ‘webpack/lib/removeAndDo’ when building a project

  1. `C:\my_project\node_modules\webpack-cli\bin\webpack.js:243
    throw err;

    Error: Cannot find module ‘webpack/lib/removeAndDo’

    When I see into source of webpack/lib I don’t see the module. So maybe webpack-cli has wrong reference?

  2. For me the issue was caused by extract-text-webpack-plugin module. Older version of this package are not compatible with webpack 4.

    As per this comment, updating extract-text-webpack-plugin should solve the issue.

    Also, with webpack-4, it is advisable to use mini-css-extract-plugin instead of extract-text-webpack-plugin

  3. I easily replicate this issue with the following Dockerfile

    Stage 1 BUILD

    FROM node:12.7-alpine AS build
    WORKDIR /usr/src/app
    COPY ClientApp/package.json ./
    RUN npm install
    COPY ClientApp/. .
    RUN npm run build

    the npm run build fails with the Cannot find module ‘webpack/lib/removeAndDo’ error on a fresh Angular CLI version 9 created website.

Comments are closed.