繁体   English   中英

Laravel 8 安装 - npm 运行开发错误

[英]Laravel 8 Installation - npm run dev Error

[webpack-cli] Error: mix.react() is now a feature flag. Use mix.js(source, destination).react() instead at React.register (F:\Server\work\reactlaravel\lrpc1\node_modules\laravel-mix\src\components\React.js:15:19) at Object.components.<computed> [as react] (F:\Server\work\reactlaravel\lrpc1\node_modules\laravel-mix\src\components\ComponentRegistrar.js:118:53) at Object.<anonymous> (F:\Server\work\reactlaravel\lrpc1\webpack.mix.js:14:5) at Module._compile (F:\Server\work\reactlaravel\lrpc1\node_modules\v8-compile-cache\v8-compile-cache.js:192:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Module.require (internal/modules/cjs/loader.js:1025:19) at require (F:\Server\work\reactlaravel\lrpc1\node_modules\v8-compile-cache\v8-compile-cache.js:159:20) at module.exports (F:\Server\work\reactlaravel\lrpc1\node_modules\laravel-mix\setup\webpack.config.js:3:5) npm ERR: code ELIFECYCLE npm ERR. errno 2 npm ERR. @ development. `mix` 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\info\AppData\Roaming\npm-cache\_logs\2021-01-06T04_36_25_320Z-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\info\AppData\Roaming\npm-cache\_logs\2021-01-06T04_36_25_340Z-debug.log

要解决此问题,您需要替换此代码。

mix.react('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

使用 webpack.mix.js 文件中的以下代码,您可以在 Laravel 应用程序根目录中找到该文件。

mix.js('resources/js/app.js', 'public/js')
    .react()
    .sass('resources/sass/app.scss', 'public/css', [
    //
    ]);

这些更改汇总在 Laravel Mix v6 中。 阅读以下内容以了解更多更改。 https://github.com/JeffreyWay/laravel-mix/blob/628f6062cceb77610b1813e3179abcbd043a4642/UPGRADE.md#update-your-npm-scripts

尝试更改 package.json 中的脚本

"scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --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 --disable-host-check --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 --config=node_modules/laravel-mix/setup/webpack.config.js"
},

有同样的问题,刚刚删除节点并再次成功安装:

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
npm run dev

来源: https://github.com/JeffreyWay/laravel-mix/issues/1072

尝试运行

npm install

然后运行

npm install && npm run dev

它帮助我解决了这个问题,顺便说一句,我正在使用 laravel 8

我之前发现了同样的问题并尝试了这个:

  1. 删除node_modules文件夹和package-lock.json
  2. 使用 npm 重新安装npm install
  3. 尝试再次运行npm run dev

有关详细信息,请参阅https://github.com/laravel-mix/laravel-mix/issues/2774

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM