【问题标题】:npm run dev not working after laravel/ui installation in laravel 8 app在 laravel 8 应用程序中安装 laravel/ui 后,npm run dev 无法正常工作
【发布时间】:2023-03-12 01:41:01
【问题描述】:

我已经在我的 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 和 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();

【问题讨论】:

标签: php laravel npm laravel-8 npm-run


【解决方案1】:

试试这个。

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-20
      • 2021-04-11
      • 2021-07-22
      • 2021-04-14
      • 1970-01-01
      • 2020-02-07
      • 2020-01-21
      • 2021-03-25
      相关资源
      最近更新 更多