luis matheus
luis matheus

Reputation: 207

'Module not found' error when running webpack

A few days ago to solve a problem with the webpack module, I had to move my global dependencies to Development dependencies, before everything was working correctly, but now when I run the webpack it returns the following error:

ERROR in (webpack)/lib/node/NodeTargetPlugin.js 
Module not found: Error: Can't resolve 'module' in '.../node_modules/webpack/lib/node'
 @ (webpack)/lib/node/NodeTargetPlugin.js 11:1-18
 @ ./node_modules/worker-loader/dist/index.js
 @ ./node_modules/worker-loader/dist/cjs.js
 @ ./node_modules/pdfjs-dist/webpack.js
 @ ./src/js/index.js
 @ multi ./src/js/index.js

I have already used the methods presented here on StackOverflow and other forums, such as delete the node_modules, yarn.lock folder, clear the cache and as mentioned above install the modules as development dependencies, but nothing worked.

This is my package.json file

{
  "name": "AgileTag",
  "version": "1.0.0",
  "description": "Web app para automatizar a criação de etiquetas",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  },
  "author": "Luis Matheus",
  "license": "MIT",
  "dependencies": {
    "@babel/core": "^7.10.5",
    "@babel/polyfill": "^7.10.4",
    "@babel/preset-env": "^7.10.4",
    "@babel/runtime-corejs3": "^7.10.5",
    "@babel/types": "^7.10.5",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.1.0",
    "core-js": "^3.6.5",
    "live-server": "^1.2.1",
    "pdfjs-dist": "^2.4.456",
    "regenerator-runtime": "^0.13.5",
    "yarn": "^1.22.4"
  },
  "devDependencies": {
    "html-webpack-plugin": "^4.3.0",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0",
    "worker-loader": "^2.0.0"
  }
}

Upvotes: 2

Views: 6085

Answers (1)

BINFAS K
BINFAS K

Reputation: 255

I got this same error before and I removed my global webpack, installed locally and run it with web pack, try that

npm remove webpack -g

npm i webpack --save-dev

npm run webpack

If you're running it with local webpack try this: delete packages and install and run.

 npm cache verify

 npm install

Upvotes: 1

Related Questions