Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid start-up command "nuxt build && nuxt start" in package.json #3638

Closed
farhan711 opened this issue Aug 6, 2018 · 4 comments
Closed
Labels

Comments

@farhan711
Copy link

farhan711 commented Aug 6, 2018

Error thrown at the time of deployment via ZipDeploy on Azure web application, I've set Node Environment with Application setting, and tried every possible way to solve this. This application use axios, nuxtjs, vueJS, Nodejs, and webpack. The error is Invalid start-up command "nuxt build && nuxt start" in package.json. Please use the format "node <script relative path>".

"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt build && nuxt start",
    "precommit": "npm run lint",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
  },
  "engines": {
    "node": "8.9.4",
    "npm": "5.6.0"
  },

I've added server.js(code is below) file and it successfully generated web.config file and iisnode.yml but still it fail to build nuxt and start npm.

const express = require('express')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000

app.set('port', port)

// Import and set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')

async function start () {
  // Init Nuxt.js
  const nuxt = new Nuxt(config)

  // Start build process in dev mode
  if (config.dev) {
    const builder = new Builder(nuxt)
    await builder.build()
  }

  // Give nuxt middleware to express
  app.use(nuxt.render)

  // Start express server
  app.listen(port, host)
  console.log('Server listening on http://' + host + ':' + port) // eslint-disable-line no-console
}

start()

Please help me solving this issue,
Many thanks.

This question is available on Nuxt community (#c7500)
@ghost ghost closed this as completed Aug 6, 2018
@ghost
Copy link

ghost commented Aug 6, 2018

This issue as been imported as question since it does not respect nuxt.js issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/nuxt.js/issues/c7500.

@ghost ghost added the cmty:question label Aug 6, 2018
@affinage-digital
Copy link

affinage-digital commented Aug 9, 2018

Solution for @farhan711

package.json >>> "start": "node server.js",

{
    "name": "my-app",
    "license": "UNLICENSED",
    "repository": {
        "type": "git",
        "url": "https://github.com/npm/cli.git"
    },
    "scripts": {
        "dev": "nuxt",
        "build": "nuxt build",
        "start": "node server.js",
        "generate": "nuxt generate"
    },
    "engines": {
        "node": "10.6.0",
        "npm": "6.1.0"
    },
    "devDependencies": {
        "jquery": "^3.3.1",
        "node-sass": "^4.9.2",
        "nuxt": "^1.4.1",
        "nuxt-sass-resources-loader": "^2.0.3",
        "sass-loader": "^7.0.3"
    },
    "dependencies": {
        "@nuxtjs/axios": "^5.3.1",
        "express": "^4.16.3",
        "lodash": "^4.17.10",
        "vue-i18n": "^8.0.0"
    }
}

server.js - "builder.build()" analogue "nuxt build" we waiting him

const { Nuxt, Builder } = require('nuxt');
const app = require('express')();
const port = process.env.port || 3000;

async function start() {
  let config = require('./nuxt.config.js');
  config.dev = false;
  config.env = {};
  config.env.baseUrl = port;
  config.axios.baseURL = 'http://' + process.env.WEBSITE_HOSTNAME;
  config.axios.browserBaseURL = 'http://' + process.env.WEBSITE_HOSTNAME;
  
  //process.env.DEBUG = 'nuxt:*';

  const nuxt = new Nuxt(config);

  const builder = new Builder(nuxt);

  await builder.build().catch(error => {
    console.error(error);
    process.exit(1);
  });
  
  app.use(nuxt.render);
  app.listen(port);
};

start();

@horihiro
Copy link

@farhan711
If you got following messages via ZipDeploy, "npm start" is not needed.

remote: Looking for app.js/server.js under site root.
remote: Using start-up script server.js
remote: Generated web.config.

But nuxt application needs to execute "nuxt build" before running.
you can run this command automatically by "postinstall": "nuxt build" in package.json If you want.

@lock
Copy link

lock bot commented Oct 31, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants