Laravelで
# npm run dev
すると
/var/www/xxx/node_modules/cross-env/src/index.js:23 SyntaxError: Unexpected token
っていうエラーが出て困りました。
解決策を調べました。
Laravel で npm run devするとSyntaxError
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# npm run dev > @ dev /var/www/xxx > npm run development > @ development /var/www/xxx > cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js /var/www/xxx/node_modules/cross-env/src/index.js:23 ) ^ 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> (/var/www/xxx/node_modules/cross-env/src/bin/cross-env.js:3:18) npm ERR! Linux 3.10.0-123.13.2.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 --hide-modules --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 --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /var/www/xxx/npm-debug.log npm ERR! Linux 3.10.0-123.13.2.el7.x86_64 npm ERR! argv "/usr/bin/node" "/bin/npm" "run" "dev" npm ERR! node v6.17.1 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! @ dev: `npm run development` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ dev script 'npm run development'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! npm run development npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /var/www/xxx/npm-debug.log |
うーん。
困った。
nodeのバージョンが古い?最新にする
nodeを調べてみると古すぎることが判明。
1 2 |
# node --version v6.17.1 |
nodeを最新にします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# npm install -g n /usr/bin/n -> /usr/lib/node_modules/n/bin/n /usr/lib └── n@7.2.2 # n latest installing : node-v16.1.0 mkdir : /usr/local/n/versions/node/16.1.0 fetch : https://nodejs.org/dist/v16.1.0/node-v16.1.0-linux-x64.tar.xz installed : v16.1.0 (with npm 7.11.2) Note: the node command changed location and the old location may be remembered in your current shell. old : /bin/node new : /usr/local/bin/node To reset the command location hash either start a new shell, or execute PATH="$PATH"こ |
これで
node 16.1.0
がインストールされました。
すぐにパスが通っていないようなので、いったん、ログアウトしてからログインします。
その後、
# npm run dev
するとちゃんと正常に動きました。
コメント