Home » vue » Laravel getting error in install vue and npm run dev

Laravel getting error in install vue and npm run dev

Posted by: admin November 26, 2021 Leave a comment

Questions:

I want to install Vue in laravel,
I run these commands and it all ok:

composer require laravel/ui:^2.4
php artisan ui vue
php artisan ui vue --auth
npm install
npm run dev

npm run dev is giving me this error and i don’t know what to do

at Object.<anonymous> (/home/alikhani97/domains/imalikhani.me/public_html/node_modules/cross-
env/src/bin/cross-env.js:3:18)
npm ERR! Linux 3.10.0-1127.10.1.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "development"
npm ERR! node v6.17.1                                                                                                   
npm ERR! npm  v3.10.10                                                                                                  
npm ERR! code ELIFECYCLE                                                                                                
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --
config=node_modules/laravel-mix/setup/webpack.config.js`                                                                               
npm ERR! Exit status 1                                                                                                  
npm ERR!                                                                                                                
npm ERR! Failed at the @ development script 'cross-env NODE_ENV=development 
node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-
mix/setup/webpack.config.js'.                                                          
                                                                                        
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> 
Answers:

First check if cross-env module is installed. If not, run:

npm install cross-env

After that you need to go to the node_modules folder. Then find cross-env folder. Go inside and find cross-env.js.

In my case it was node_modules/cross-env/dist/bin/cross-env.js

You need to change path to cross-env.js in scripts section in your package.json file.

{
  "private": true,
  "scripts": {
    "dev": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

........

}

If the above changes are already up to date then remove the directory

node_modules

and file

package-lock.json

update your node version to 8 and then

run command npm install and then npm run dev