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.
2
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.
You can try the following:
Check ./Webpack directory and make sure that webpack.[object Object].js exists there.
./Webpack
webpack.[object Object].js
Check webpack.config.js for any errors (syntax errors, etc.).
webpack.config.js
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 install -g webpack webpack-cli
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:
node_modules
dist
package-lock.json
npm i
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
Click here to cancel reply.
2
Answers
Have you tried using npm link?
This should link the globally installed webpack to your project.
Alternatively, try
without the -g to install it locally.
You can try the following:
Check
./Webpack
directory and make sure thatwebpack.[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:Try deleting the
node_modules
folder, thedist
folder andpackage-lock.json
, then re-runnpm i
. So, do the following:Try installing webpack locally as devDependencies by running the following: