Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross-env/dist/index.js:42 unexpected token }

A little background: I'm developing a Laravel 5 application. I'm developing locally on Windows 7 using Homestead (using Vagrant/VirtualBox) and deploying to an Amazon EC2 instance through CodePipeline.

While trying to get Laravel Mix working locally, I kept running into a cacophony of errors that eventually led me to the solution of installing cross-env globally rather than including it in the devDependencies in package.json. Of course, this also means that my Amazon deployment needed to be updated to that setup as well. None of this is really relevant except to explain that cross-env is installed globally on my deployment, in case that's relevant.

My package.json:

{
    "private": true,
    "scripts": {
        ...
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.16.2",
        "bootstrap-sass": "^3.3.7",
        "jquery": "^3.1.1",
        "laravel-mix": "^1.0",
        "lodash": "^4.17.4",
        "vue": "^2.1.10"
    }
}

My deployment to AWS fails on npm run production with the following error:

[stderr]/usr/lib/node_modules/cross-env/dist/index.js:42
[stderr]    });
[stderr]    ^
[stderr]SyntaxError: Unexpected token }

What could be causing this issue? And how can I resolve it? I highly doubt that there's actually a syntax error in cross-env.

like image 641
CGriffin Avatar asked Jan 04 '23 02:01

CGriffin


1 Answers

I had the same problem and i could fix it by updating node and re-installing npm.

Steps that worked for me:

Update Node using a package manager:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Then fresh install:

rm -rf node_modules && npm cache clean --force && npm install

Hope it helps

like image 169
JoseSilva Avatar answered Jan 05 '23 17:01

JoseSilva