0

我已经在我的 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

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

6.14.4 (npm -v)

v10.19.0(节点-v)

我试图重新安装 npm 和节点。但是重装之后还是有错误

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();
4

2 回答 2

0

你只需要更新nodejs。(目前在 v14.15.4 上)

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

于 2021-01-25T21:31:13.507 回答
0

试试这个。

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
于 2021-02-28T23:17:53.450 回答