在 laravel 8 应用中安装 laravel/ui 后 npm 运行 dev 不工作
npm run dev not working after laravel/ui installation in laravel 8 app
我已经使用
在我的 laravel 8 应用程序中安装了 laravel/ui
composer require laravel/ui
php artisan ui:auth
php artisan ui bootstrap
后来我做了
npm install && npm run dev
npm install 命令工作正常但是 运行ning npm 运行 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 的 public 文件夹中呈现。我正在使用
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();
你只需要更新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
我一直没搞清楚到底是什么问题,不过我是这样解决的
在安装之前 Laravel ui 我的 devDependencies 是这样的
"devDependencies": {
"axios": "^0.19",
"cross-env": "^7.0",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.19",
"resolve-url-loader": "^3.1.0",
"vue-template-compiler": "^2.6.14"
}
然后我安装了 Laravel UI 并使用了 bootstrap auth。安装后,我的 devDependencies 更改为此,我无法 运行 “npm 运行 dev”。它显示了这样的错误,
[webpack-cli] Error: Unknown option '--hide-modules'
[webpack-cli] Run 'webpack --help' to see available commands and options
然后我使用“npm update”更新了我所有的 npm 包,还更新了 运行ning Laravel mix 的 npm 脚本。现在我的 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": {
"@popperjs/core": "^2.10.2",
"axios": "^0.26.0",
"bootstrap": "^5.1.3",
"cross-env": "^7.0",
"laravel-mix": "^6.0.43",
"lodash": "^4.17.19",
"resolve-url-loader": "^3.1.0",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vue-template-compiler": "^2.6.14",
"webpack-cli": "^4.9.2"
}
}
我已经使用
在我的 laravel 8 应用程序中安装了 laravel/uicomposer require laravel/ui
php artisan ui:auth
php artisan ui bootstrap
后来我做了
npm install && npm run dev
npm install 命令工作正常但是 运行ning npm 运行 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 的 public 文件夹中呈现。我正在使用
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();
你只需要更新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
我一直没搞清楚到底是什么问题,不过我是这样解决的
在安装之前 Laravel ui 我的 devDependencies 是这样的
"devDependencies": {
"axios": "^0.19",
"cross-env": "^7.0",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.19",
"resolve-url-loader": "^3.1.0",
"vue-template-compiler": "^2.6.14"
}
然后我安装了 Laravel UI 并使用了 bootstrap auth。安装后,我的 devDependencies 更改为此,我无法 运行 “npm 运行 dev”。它显示了这样的错误,
[webpack-cli] Error: Unknown option '--hide-modules'
[webpack-cli] Run 'webpack --help' to see available commands and options
然后我使用“npm update”更新了我所有的 npm 包,还更新了 运行ning Laravel mix 的 npm 脚本。现在我的 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": {
"@popperjs/core": "^2.10.2",
"axios": "^0.26.0",
"bootstrap": "^5.1.3",
"cross-env": "^7.0",
"laravel-mix": "^6.0.43",
"lodash": "^4.17.19",
"resolve-url-loader": "^3.1.0",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vue-template-compiler": "^2.6.14",
"webpack-cli": "^4.9.2"
}
}