【问题标题】:Laravel Mix "npm run dev module build failed, cannot find module ... but all are installedLaravel Mix "npm run dev module build failed, 找不到模块...但是都安装好了
【发布时间】:2021-12-29 04:11:27
【问题描述】:

我有什么:

  1. macOS 大苏尔
  2. 带有 nvm 的节点 14(我也尝试了 17)
  3. npm 8.1.3
  4. Laravel 8

package.json

{
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "prod": "npm run production",
    "production": "mix --production"
  },
  "devDependencies": {
    "axios": "^0.21.4",
    "babel-loader": "^8.2.3",
    "bootstrap": "^4.6.0",
    "jquery": "^3.6",
    "laravel-mix": "^6.0.6",
    "lodash": "^4.17.19",
    "mini-css-extract-plugin": "^2.4.5",
    "popper.js": "^1.16.1",
    "postcss": "^8.1.14",
    "resolve-url-loader": "^3.1.2",
    "sass": "^1.32.11",
    "sass-loader": "^11.0.1",
    "vue": "^2.6.12",
    "vue-loader": "^15.9.8",
    "vue-template-compiler": "^2.6.12"
  },
  "dependencies": {
    "vuetify": "^2.6.0"
  }
}

我做了什么:

npm i

npm run dev // or npm run watch or npm run production, same error

错误(babel-loader 和 mini-css-extract-plugin 的模块构建失败):

ERROR in ../../../../Websites_#02/websites/dev.crost.it/src/resources/js/app.js
Module build failed: Error: Cannot find module '/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/babel-loader/lib/index.js'
Require stack:
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/ProgressPlugin.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/index.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/lib/webpack-cli.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/lib/bootstrap.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/bin/cli.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/ProgressPlugin.js:412:9
    at Hook.eval [as call] (eval at create (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at Hook.CALL_DELEGATE [as _call] (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/Hook.js:14:14)
    at NormalModule._doBuild (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:802:24)
    at NormalModule.build (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:956:15)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/Compilation.js:1367:12
    at NormalModule.needBuild (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:1243:32)
    at Compilation._buildModule (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/Compilation.js:1348:10)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/util/AsyncQueue.js:303:10
    at Hook.eval [as callAsync] (eval at create (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/Hook.js:18:14)
    at AsyncQueue._startProcessing (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/util/AsyncQueue.js:293:26)

ERROR in ../../../../Websites_#02/websites/dev.crost.it/src/resources/sass/app.scss
Module build failed: Error: Cannot find module '/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/laravel-mix/node_modules/mini-css-extract-plugin/dist/loader.js'
Require stack:
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/ProgressPlugin.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/index.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/lib/webpack-cli.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/lib/bootstrap.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack-cli/bin/cli.js
- /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/ProgressPlugin.js:412:9
    at Hook.eval [as call] (eval at create (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at NormalModule._doBuild (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:802:24)
    at NormalModule.build (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:956:15)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/Compilation.js:1367:12
    at NormalModule.needBuild (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/NormalModule.js:1243:32)
    at Compilation._buildModule (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/Compilation.js:1348:10)
    at /Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/util/AsyncQueue.js:303:10
    at Hook.eval [as callAsync] (eval at create (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncQueue._startProcessing (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/util/AsyncQueue.js:293:26)
    at AsyncQueue._ensureProcessing (/Volumes/Websites_#02/websites/dev.crost.it/src/node_modules/webpack/lib/util/AsyncQueue.js:280:12)
    at processImmediate (node:internal/timers:464:21)

webpack compiled with 2 errors

我尝试解决的问题:

npm link babel-loader // npm link mini-css-extract-plugin
rm -rf node_module && rm -rf package-lock.json && npm install

所有项目都出现同样的错误,我也尝试过:

  1. 使用 -g 选项全局安装模块,没有任何变化
  2. 删除 nvm npm 并使用 homebrew 重新安装

【问题讨论】:

标签: laravel npm webpack babel-loader mini-css-extract-plugin


【解决方案1】:

你能试试npm install -D babel-loader @babel/core @babel/preset-env webpack吗?

我在这里找到了这个答案:https://stackoverflow.com/a/62933979/14807111

【讨论】:

  • 谢谢,但没有任何改变...
  • 我不确定,但您可以为该软件包提供“错误”的 nodejs 版本。尝试降级。
猜你喜欢
  • 2021-07-22
  • 2023-02-02
  • 2021-04-11
  • 2017-09-22
  • 1970-01-01
  • 1970-01-01
  • 2021-10-01
  • 2015-12-07
  • 2021-09-13
相关资源
最近更新 更多