Search code examples
vue.jswebpackproduction

npm run production not working after hosting the application


When I run npm production on my localhost, everything works good but after hosting the application I try to run the same command (npm run prod or npm run production), I get always the same error message.

// node_modules/laravel-mix/setup/webpack.config.js

/**
 * As our first step, we'll pull in the user's webpack.mix.js
 * file. Based on what the user requests in that file,
 * a generic config object will be constructed for us.
 */

require('../src/index');
require(Mix.paths.mix());

/**
 * Just in case the user needs to hook into this point
 * in the build process, we'll make an announcement.
 */

Mix.dispatch('init', Mix);

/**
 * Now that we know which build tasks are required by the
 * user, we can dynamically create a configuration object
 * for Webpack. And that's all there is to it. Simple!
 */

let WebpackConfig = require('../src/builder/WebpackConfig');

module.exports = new WebpackConfig().build();

//package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "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 --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 --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19.0",
        "bootstrap": "^4.3.1",
        "cross-env": "^5.2.1",
        "jquery": "^3.4.1",
        "laravel-mix": "^1.0",
        "lodash": "^4.17.15",
        "popper.js": "^1.15.0",
        "vue": "^2.6.10",
        "vue-template-compiler": "^2.6.10"
    },
    "dependencies": {
        "aos": "^2.3.4",
        "laravel-echo": "^1.6.1",
        "laravel-vue-pagination": "^2.3.1",
        "node-sass": "^4.12.0",
        "pusher-js": "^4.4.0",
        "socket.io-client": "^2.3.0",
        "vee-validate": "^2.2.15",
        "vue-passport": "^1.0.13",
        "vue-resource": "^1.5.1",
        "vue-router": "^3.1.3",
        "vue-simple-spinner": "^1.2.8",
        "vue-sweetalert2": "^1.6.4",
        "vue-top-progress": "^0.7.0",
        "vuetify": "^1.5.18",
        "webpack": "^3.12.0"
    }
}

Error message:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --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!     /root/.npm/_logs/2019-10-10T13_38_27_403Z-debug.log

Solution

  • you do not need to run a node server separately for your vueis to work, all you need to do is to build it and include it into your laravel application like any other JavaScript file, and if you want to be involved in server side rendering you can use the laravel server side library for such or look into phpv8 engine