NPM 安装失败 Laravel 8

NPM Installation Failed With Laravel 8

我想在我的 Laravel 8 项目上执行 运行 npm run dev 命令,但出现此错误:

[webpack-cli] Error: Unknown option '--hide-modules'
[webpack-cli] Run 'webpack --help' to see available commands and options
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpa
ck.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User 1\AppData\Roaming\npm-cache\_logs21-07-03T05_59_56_150Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User 1\AppData\Roaming\npm-cache\_logs21-07-03T05_59_56_264Z-debug.log

我的 package.json 是这样的:

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@fortawesome/fontawesome-free": "^5.15.1",
        "axios": "^0.21.1",
        "bootstrap": "^4.5.2",
        "jquery": "^3.5.1",
        "laravel-mix": "^4.1.4",
        "lodash": "^4.17.20",
        "node-sass": "^4.14.1",
        "popper.js": "^1.16.1",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.29.0",
        "sass-loader": "^7.3.1",
        "vue": "^2.6.12",
        "vue-template-compiler": "^2.6.12",
        "webpack": "^4.44.2",
        "webpack-cli": "^4.7.2"
    },
    "dependencies": {
        "@fancyapps/fancybox": "^3.5.7",
        "@wiris/mathtype-tinymce5": "^7.24.1",
        "bootstrap-fileinput": "^5.1.3",
        "chosen-js": "^1.8.7",
        "copy-to-clipboard": "^3.3.1",
        "counterup2": "^1.0.4",
        "croppie": "^2.6.5",
        "font-awesome": "^4.7.0",
        "highcharts": "^8.2.0",
        "jquery-clock-timepicker": "^2.3.2",
        "num2persian": "^3.2.2",
        "production": "0.0.2",
        "select2": "^4.0.13",
        "simplebar": "^5.3.0",
        "slick-carousel": "^1.8.1",
        "sweetalert2": "^8.19.0",
        "tinymce": "^5.5.1",
        "tooltipster": "^4.2.8"
    }
}

我尝试删除 node_modules 文件夹并再次 运行 命令 npm installnpm run dev 但没有解决问题。

至少,Laravel 8 的最新版本对 package.json 中的脚本部分进行了更改,以利用 Laravel Mix 的更新版本。

在您的 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": {
        "@fancyapps/fancybox": "^3.5.7",
        "@fortawesome/fontawesome-free": "^5.15.3",
        "@wiris/mathtype-tinymce5": "^7.26.1",
        "axios": "^0.21.1",
        "bootstrap": "^5.0.2",
        "bootstrap-fileinput": "^5.2.2",
        "chosen-js": "^1.8.7",
        "copy-to-clipboard": "^3.3.1",
        "counterup2": "^1.0.4",
        "croppie": "^2.6.5",
        "highcharts": "^9.1.2",
        "jquery": "^3.6.0",
        "jquery-clock-timepicker": "^2.4.0",
        "laravel-mix": "^6.0.25",
        "lodash": "^4.17.21",
        "node-sass": "^6.0.1",
        "num2persian": "^3.2.2",
        "popper.js": "^1.16.1",
        "postcss-import": "^14.0.2",
        "production": "0.0.2",
        "resolve-url-loader": "^4.0.0",
        "sass": "^1.35.1",
        "sass-loader": "^12.1.0",
        "select2": "^4.0.13",
        "simplebar": "^5.3.4",
        "slick-carousel": "^1.8.1",
        "sweetalert2": "^11.0.18",
        "tailwindcss": "^2.2.4",
        "tinymce": "^5.8.2",
        "tooltipster": "^4.2.8",
        "vue": "^2.6.14",
        "vue-template-compiler": "^2.6.14",
        "webpack": "^5.42.0",
        "webpack-cli": "^4.7.2"
    }
}

第一次新安装 npm。

npm install

请运行命令。

npm i vue-loader

现在这个命令 运行.

npm run dev