1

I'm stucked with this problem and I need to fix it already so any tips will be truly appreciated.

I've my project made with Laravel and Vue, with an image container in Docker. The app is hosted in AWS.

The problem I'm facing is that I can't deploy the app to production using the follow command: ssh ec2-user@13.58.231.51 'cd /var/www/mevym/; ./deploy.sh'

The curious part is that if I run npm run production it works perfectly fine.

I already tried every single solutions from similar threads, like this one: How to solve npm error "npm ERR! code ELIFECYCLE" but nothing worked for me.

This is my package.json:

    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
    },

Just in case, here it's my webpack.mix.js:

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        require('postcss-import'),
        require('tailwindcss'),
    ])
    .webpackConfig(require('./webpack.config'));

.deploy.sh:

# Enter maintenance mode
(php artisan down --message 'The app is being (quickly!) updated. Please try again in a minute.') || true

    # Update branch
    git fetch --all
    git reset --hard origin/main

    # Make storage writable
    sudo chmod -R 777 ./storage

    # Install dependencies based on lock file
    composer install --no-interaction --prefer-dist --optimize-autoloader

    # JS dependencies
    npm install

    # Migrate database
    php artisan migrate --force

    # Compile assets
    npm run prod

    # Clear cache
    php artisan optimize

    # Reload PHP to update opcache
    echo "" | sudo -S service php-fpm reload
# Exit maintenance mode
php artisan up

echo "Application deployed!"

And finally the error:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ production 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/ec2-user/.npm/_logs/2021-01-08T18_49_06_563Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ prod: `npm run production`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Thanks in advance.

Franco Alemandi
  • 235
  • 4
  • 12
  • Are the relevant dependencies (webpack, cross-env) installed as prod dependencies (or are you running `npm i` rather than `npm i --prod` when building)? What is the content of `deploy.sh`? – Zac Anger Jan 08 '21 at 19:08
  • Hi @ZacAnger I'm running ```npm i``` instead of ```npm i--prod```. I already edited the question when the content of ```.deploy.sh``` – Franco Alemandi Jan 08 '21 at 19:10
  • Is your NPM version in production the same as your local version? That would be where I check first. – Daron Spence Jan 08 '21 at 19:15
  • Interesting. Are you able to access the log files the error message mentions, and if so do they have any more detail? And when you say that `npm run production` works, does that mean it works in production, but the alias to it doesn't? – Zac Anger Jan 08 '21 at 19:16
  • did you install yarn in your production – Boni Jan 08 '21 at 19:19
  • sometimes npm did not work so you can try with yarn that might help. – Boni Jan 08 '21 at 19:20
  • @Dar It was working before so I guess they both have the same version. Although I'll check it out and keep you in touch. @ZacAnger I checked the log yesterday and I can assure you that it doesn't contain any more details than the mentioned in the question. In refference to your other question, I mean that I can run the command and it seems to work: ```DONE Compiled successfully in 42022ms``` but when I run the command that actually deploys it to production everything just goes crazy. – Franco Alemandi Jan 08 '21 at 19:22

1 Answers1

0

In case that anyone is just going through the same and checked every other alternatives here, it was a server memory problem. We just had to clean it and we were ready to keep it going. Apparently after several deploys it ran out of space.

Franco Alemandi
  • 235
  • 4
  • 12