4

I'm trying to start a NextJS application on my Node server using Plesk but it is not working. I activated NodeJS for my Plesk environment, and I was able to run npm install and npm build, but now, when I try to start the application, Plesk only shows "Please wait" and stays like that with no change, I have been waiting for more than 2 hours now, but I don't get any results, no errors, nothing.

The only issue I can think of is that, according to what I could find, the Application startup file and the package.json file should be in the same directory, the root folder, but in my case this is not possible. I have my package.json in the root directory, but the startup file for NextJS, index.js, is inside the pages folder. I tested building and starting the app locally and everything works fine, I don't understand why it's not working with Plesk.

Carlos G
  • 479
  • 1
  • 8
  • 19

3 Answers3

5

I was able to fix this after correcting the startup file, it should be "node_modules/.bin/next" and not "pages/index.js".

Also when you start your app, Plesk will tell you to wait. Just check the site and make sure it is running, if it is, you can close Plesk.

Carlos G
  • 479
  • 1
  • 8
  • 19
  • This solution works if you are not using a server.js file. If you are, like I ended up doing. server.js will be your startup file. – Carlos G Feb 21 '21 at 03:16
  • 1
    using "node_modules/.bin/next" does work but if you call it without parameter it starts in DEV mode. This is not what you want in production. To find my way around I've had to clone that script (saved it in my projects root folder), changed the defaultCommand to "start", and updated all the require('../ ..) to require('node_modules/next/dist/ ...). This works now as it should inclusive SSR and ISR. No custom server needed. – Novazembla Jun 02 '21 at 14:31
  • what path u set for document root ? – Shamseer Ahammed Mar 24 '22 at 06:38
  • 1
    @CarlosG can you please share your plesk settings for document root, application mode, etc? – FabricioG Dec 16 '22 at 01:48
1

You might need to install Express in your Next.js

You may refer to this repo fmi @ https://github.com/zeit/next.js/tree/canary/examples/custom-server-express

If you're referring to the package.json's command we'll have:

  • dev
  • build
  • start

In Plesk's Node Application extension.

  1. Website & Domains > "Your Domain" > Enable Node.js
  2. Simply set server.js as my Application Startup File.
  3. Ensure that all dependencies is installed using "Npm Install" helper.
  4. You must run build command before start command.

Screenshot: enter image description here

Helpful NPM/Plesk reference:

Mavichow
  • 1,213
  • 17
  • 41
  • Thank you very much. But when doing so, I'm opting out of next and some usefull features like routing / serverless routes, right? I'd like to stay with nextjs. – K. D. May 21 '20 at 17:58
  • 1
    Hi, I'm allow to use serverless routes or pages/api function with Plesk. – Mavichow May 23 '20 at 18:01
  • This is really helpfull. Is there a way to your knowledge to deploy automatically from Git repo. Please built-in Git repository linking supports copying file from Git repo to project directory in plesk. But how do we automate call to `npm install` and `npm start`. Also, after setting startup file to `server.js`, plesk immediately run that file which starts the server so we can't use `npm start`, it says port already in use which indeed it is. – shashwat Oct 17 '21 at 05:10
  • After the we integrate GIT in Plesk. I have set "additional deployment action" `(PATH=/opt/plesk/node/10/bin:$PATH; npm install && npm run build &> npm.log) touch tmp/restart.txt` tmp/restart.txt is to ask Node.js to restart it. – Mavichow Oct 17 '21 at 09:37
0

If you're having issues with directories, you can create a standalone build of your next.js app by editing the next.config.js file:

module.exports = {
  output: 'standalone',
}

(See the documentation https://nextjs.org/docs/advanced-features/output-file-tracing)

It will require a few other steps but at least all your files will be together. (See https://mytchall.dev/removing-the-build-folders-when-deploying-next-js-on-plesk/)

cryptoboi
  • 3
  • 2