skip to Main Content

I keep getting the following error when I try to run webpack task runner in visual studio 2022.

[webpack-cli] Error: Cannot find module './Webpack/webpack.[object Object].js'

Following is my folder structure and I have tried using npm install -g webpack.
No css or js files are missing.

enter image description here

2

Answers


  1. Have you tried using npm link?

    npm link webpack
    

    This should link the globally installed webpack to your project.

    Alternatively, try

    npm install webpack
    

    without the -g to install it locally.

    Login or Signup to reply.
  2. You can try the following:

    Check ./Webpack directory and make sure that webpack.[object Object].js exists there.

    Check webpack.config.js for any errors (syntax errors, etc.).

    Check the compatibility of webpack and webpack-cli with other dependencies in your project.

    If you installed webpack and webpack-cli globally (i.e., npm install -g webpack webpack-cli), run the following:

    npm link webpack
    npm link webpack-cli
    

    Try deleting the node_modules folder, the dist folder and package-lock.json, then re-run npm i. So, do the following:

    rm -rf node_modules
    rm -f package-lock.json
    rm -rf dist
    
    npm cache clean --force
    
    npm i
    

    Try installing webpack locally as devDependencies by running the following:

    npm install --save-dev webpack webpack-cli
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search