Nuxt.js: Server Rendered Deployment (Universal)

Created on 14 Feb 2018  路  19Comments  路  Source: nuxt/nuxt.js

Hi, had a look around at the issues/documentation, but couldn't find anything specific to my question:

What do we need to deploy to our server to run it in Server Rendered Deployment (Universal)?

image

Does this whole folder have to be deployed to the server for it to work (seems quite a lot if we have to upload all the source code to the server), or do we need to just deploy the .nuxt folder?

Any help/how it's meant to be done would be appreciated :)

This question is available on Nuxt.js community (#c2456)
documentation stale

Most helpful comment

If you running realtime server side renderer, after 'npm run build', you can copy .nuxt folder (without sources), nuxt config and package.json to your server.
Or you can copy sources and build it on server, but that way you can hang your server if it not powerfull enough.
If you running pre-generated server side renders, just upload dist folder to your static server path.

All 19 comments

You have to copy your source code (or git clone) on your server and Node.js must be install on it.

Then execute the following commands:

npm install
npm run build
npm run start

If you running realtime server side renderer, after 'npm run build', you can copy .nuxt folder (without sources), nuxt config and package.json to your server.
Or you can copy sources and build it on server, but that way you can hang your server if it not powerfull enough.
If you running pre-generated server side renders, just upload dist folder to your static server path.

Okay great - I'll take a look!

Is is possible to deploy this to azure hosting? If so do you know how to? I keep getting

"You do not have permission to view this directory or page."

After running nuxt build
my deployment folder structure is:

.nuxt/dist -> the builded proyect
nuxt.config.js
package.json
static -> static folder
In the server you need to run npm install

I serve it in an Ubuntu Server at Digital Ocean, node.js need to be updated or it will fail.

If you have a file to handle sessions i think you need to upload it.

Hope it is usefull. I just uploaded a project today and had the same question.

Which files need to be deployed after the build? I'm seeing errors.

Here's what I've tried from info in this thread. Ran build on dev server and then copied the following folders/files to my production server.

.nuxt
package.json
nuxt.config.js

On the production server, ran yarn to install packages and now have the additional files/folders.

yarn.lock

Running yarn start on production server gives me:

$ yarn start
yarn run v1.10.1
$ cross-env NODE_ENV=production node server/index.js
internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module '/www/my-site/server/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
error Command failed with exit code 1.

@RichAyotte you have wrong start script, cross-env NODE_ENV=production node server/index.js - this is for the case when you use koa or express with nuxt
you probably need to have cross-env NODE_ENV=production nuxt start there, although this is not right for production - you need to start it with process manager.
Take a look here https://gist.github.com/DreaMinder/e9fc988295378d8373521a93c3ca6d18

I am using Koa with Nuxt. Created the app with Nuxt 2.2.0 by following https://nuxtjs.org/guide/installation

Maybe a bug is 2.2.0?

I just noticed that your start script is node_modules/nuxt/bin/nuxt-start which works. Thanks for that gist!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@DreaMinder The latest version of Nuxt broke your script. node_modules/nuxt-start/bin/nuxt-start no longer exists.

It can now all be run in a single node process now too instead of splitting the api out.

@RichAyotte no, I believe you wrong.
node_modules/nuxt/bin/nuxt-start - this doesn't exists in new nuxt version, yes.
node_modules/nuxt-start/bin/nuxt-start - but this should work. Note that you should have separate package installed called nuxt-start (lite production version of nuxt).

Oh geez, I didn't notice that nuxt-start package - I thought I was running /nuxt/bin/nuxt-start. Thanks again.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 馃晲Pending will not be automatically marked as stale.

BTW, if someone reading this, for [email protected] there should be new path to start script (with .js extension)
node_modules/nuxt-start/bin/nuxt-start.js

Hi,
I follow @DreaMinder 's comment. yarn install worked fine.
Now when I called yarn start, gave me error message "Cannnot find module ~/modules/typescript.js"

I am using typescript so I have typescript.js under modules dir.

Any ideas?

BTW, if someone reading this, for [email protected] there should be new path to start script (with .js extension)
node_modules/nuxt-start/bin/nuxt-start.js

How about [email protected]?

I didn't see ./node_modules/nuxt-start folder for [email protected].

@ndro see this comment https://github.com/nuxt/nuxt.js/issues/2835#issuecomment-439725489
I'm using nuxt-start dependency for production. If you want to use fat-dev-version of nuxt, you should use:

node_modules/nuxt/bin/nuxt.js

@DreaMinder , Yes, you right.

I've been using this node_modules/nuxt/bin/nuxt.js because I don't have nuxt-start.
So, when I'm using pm2 with ecosystem.config.js, what I do is just like this:

{
    name: 'name-your-page',
    port: 1111, <-- your port
    script: './node_modules/nuxt/bin/nuxt.js',
    cwd: './folder-of-your-node-app',

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'start', <-- add this argument for nuxt start
    ....
    (other option)
},

and it's work well :+1: (for me :smiley: )

I'm having an issue with that kind of deployement with vuex.
It seems the build function does not include Stores in the .nuxt folder (the server.js files refers to ../store/index.js).
I have to copy the store folder as well in order to make it works.

Is this something "normal" ? I can't find any informations about it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maicong picture maicong  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

bimohxh picture bimohxh  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

vadimsg picture vadimsg  路  3Comments