Next.js Discord

Discord Forum

systemd issue

Unanswered
Pixiebob posted this in #help-forum
Open in Discord
PixiebobOP
I have a fresh ubuntu 24.04 install with nginx, node.js 20.17, react, express, and next.js

sudo -u serviceaccount bash -c "/usr/bin/node --inspect /var/www/project/server.js"
Debugger listening on ws://127.0.0.1:9229/ea741072-3926-4472-ab64-0c0bf310bae4
For help, see: https://nodejs.org/en/docs/inspector
App running on http://localhost:3000
 ○ Compiling / ...

warn - The `content` option in your Tailwind CSS configuration is missing or empty.
warn - Configure your content sources or your generated CSS will be missing styles.
warn - https://tailwindcss.com/docs/content-configuration
 ✓ Compiled / in 6.6s (543 modules)
 GET / 200 in 6935ms
 ○ Compiling /favicon.ico ...
 ✓ Compiled /favicon.ico in 3.5s (303 modules)
 GET /favicon.ico 200 in 3630ms


But when I run it with systemd, I get the following error repeatedly:

Started Node.js App.

Error: Could not find a production build in the '.next' directory. 
Try building your app with 'next build' before starting the production server. 
https://nextjs.org/docs/messages/production-start-no-build-id

    at setupFsCheck (/var/www/project/node_modules/next/dist/server/lib/router-utils/filesystem.js:151:19)
    at async initialize (/var/www/project/node_modules/next/dist/server/lib/router-server.js:62:23)
    at async NextCustomServer.prepare (/var/www/project/node_modules/next/dist/server/next.js:242:28)

Node.js v20.17.0


Heres the folder its talking about:

cd /var/www/project/
ll
total 68
drwxrwx---  4 serviceaccount webgroup  4096 Sep 18 05:11 ./
drwxr-xr-x  4 root           root      4096 Sep 16 03:47 ../
drwxrwx---  5 serviceaccount webgroup  4096 Sep 16 07:38 frontend/
drwxrwx--- 85 serviceaccount webgroup  4096 Sep 16 06:44 node_modules/
-rw-rw----  1 serviceaccount webgroup 41336 Sep 16 08:06 package-lock.json
-rw-rw----  1 serviceaccount webgroup   302 Sep 16 06:44 package.json
-rw-rw----  1 serviceaccount webgroup   548 Sep 18 05:11 server.js

cd frontend/
ll
total 252
drwxrwx---   5 serviceaccount webgroup   4096 Sep 16 07:38 ./
drwxrwx---   4 serviceaccount webgroup   4096 Sep 18 05:11 ../
-rw-rw----   1 serviceaccount webgroup     61 Sep 16 05:10 .eslintrc.json
-rw-rw----   1 serviceaccount webgroup    391 Sep 16 05:10 .gitignore
drwxrwx---   6 serviceaccount webgroup   4096 Sep 18 05:43 .next/
-rw-rw----   1 serviceaccount webgroup   1450 Sep 16 05:10 README.md
drwxrwx---   3 serviceaccount webgroup   4096 Sep 16 05:10 app/
-rw-rw----   1 serviceaccount webgroup    228 Sep 16 05:10 next-env.d.ts
-rw-rw----   1 serviceaccount webgroup     92 Sep 16 05:10 next.config.mjs
drwxrwx--- 318 serviceaccount webgroup  12288 Sep 16 05:12 node_modules/
-rw-rw----   1 serviceaccount webgroup 188691 Sep 16 05:12 package-lock.json
-rw-rw----   1 serviceaccount webgroup    520 Sep 16 05:10 package.json
-rw-rw----   1 serviceaccount webgroup    135 Sep 16 05:10 postcss.config.mjs
-rw-rw----   1 serviceaccount webgroup    395 Sep 16 05:10 tailwind.config.ts
-rw-rw----   1 serviceaccount webgroup    574 Sep 16 05:10 tsconfig.json

cd .next
ll
total 60
drwxrwx--- 6 serviceaccount webgroup  4096 Sep 18 05:43 ./
drwxrwx--- 5 serviceaccount webgroup  4096 Sep 16 07:38 ../
-rw-r--r-- 1 serviceaccount nogroup     17 Sep 18 05:43 app-build-manifest.json
-rw-r--r-- 1 serviceaccount nogroup    294 Sep 18 05:43 build-manifest.json
drwxrwx--- 5 serviceaccount webgroup  4096 Sep 16 05:13 cache/
-rw-r--r-- 1 serviceaccount nogroup     20 Sep 18 05:43 package.json
-rw-r--r-- 1 serviceaccount nogroup      2 Sep 18 05:43 react-loadable-manifest.json
drwxr-xr-x 2 serviceaccount nogroup   4096 Sep 18 05:43 server/
drwxr-xr-x 4 serviceaccount nogroup   4096 Sep 18 05:43 static/
-rw-r--r-- 1 serviceaccount nogroup  17460 Sep 18 05:43 trace
drwxr-xr-x 2 serviceaccount nogroup   4096 Sep 18 05:43 types/

7 Replies

PixiebobOP
[Unit]
Description=Node.js App Service
After=network.target

[Service]
User=serviceaccount
Group=webgroup
WorkingDirectory=/var/www/project
ExecStart=/usr/bin/node --inspect /var/www/project/server.js
Environment=NODE_ENV=production
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target


Heres the service file
PixiebobOP
I still need help with this
PixiebobOP
I still still need help with this
Asian black bear
Our rules don't allow you to bump more than once a day, so please adhere to them.
i suspect the server is looking for the .next folder in the working directory, so using WorkingDirectory=/var/www/project should be able to fix the issue