在laravel 8 应用程序中安装laravel/ui 后,npm run dev 不起作用

问题描述

我已经使用

在我的 laravel 8 应用程序中安装了 laravel/ui
composer require laravel/ui
PHP artisan ui:auth
PHP artisan ui bootstrap

后来我做了

npm install && npm run dev

npm install 命令工作正常,但在运行 npm run dev 时,

它产生以下错误

> @ dev /home/shreyas/Documents/laravel-projects/laracast-course/register-user
> npm run development


> @ development /home/shreyas/Documents/laravel-projects/laracast-course/register-user
> mix

[webpack-cli] /home/shreyas/Documents/laravel-projects/laracast-course/register-user/node_modules/laravel-mix/src/Mix.js:18
    static _primary = null;
                    ^

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at NativeCompileCache._moduleCompile (/home/shreyas/Documents/laravel-projects/laracast-course/register-user/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/home/shreyas/Documents/laravel-projects/laracast-course/register-user/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (/home/shreyas/Documents/laravel-projects/laracast-course/register-user/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at module.exports (/home/shreyas/Documents/laravel-projects/laracast-course/register-user/node_modules/laravel-mix/setup/webpack.config.js:2:17)
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!     /home/shreyas/.npm/_logs/2021-01-12T09_20_27_344Z-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!     /home/shreyas/.npm/_logs/2021-01-12T09_20_27_447Z-debug.log

由于这个错误,app 没有编译任何东西来从 laravel 的公共文件夹渲染。我正在使用

6.14.4 (npm -v)

v10.19.0 (node -v)

我尝试重新安装 npm 和 node。但是重新安装后,错误仍然存​​在

webpack.mix.js 文件

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean,fluent API for defining some Webpack build steps
 | for your Laravel application. By default,we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

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

解决方法

你只需要更新nodejs。 (当前版本为 v14.15.4)

使用 sudo apt-get install -y nodejs 并确认您是最新的 nodejs -v;然后再试一次。

,

试试这个。

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