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

[BUG] Local serving doesn't work #70

Open
LevYas opened this issue Jan 24, 2024 · 8 comments
Open

[BUG] Local serving doesn't work #70

LevYas opened this issue Jan 24, 2024 · 8 comments
Assignees

Comments

@LevYas
Copy link

LevYas commented Jan 24, 2024

Describe The Bug

I was unable to run the project locally in production mode. The Development mode works fine.

To Reproduce

From the clean state, execute "yarn install" and "yarn build".
As per instructions, try to run yarn start. That will produce the error:

"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.

Ok, se node .next/standalone/server.js. Output (I'm on Windows):

PS D:_My\excalith-start-page> node .next/standalone/server.js
▲ Next.js 14.0.4

This time the server starts, but the page doesn't load - can't find files. Console errors:

Uncaught (in promise) TypeError: Cannot destructure property 'country' of '(intermediate value)' as it is null.
GET http://localhost:3000/_next/static/css/dec7afba07758c41.css net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/css/607fb85db1ac148f.css net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/webpack-4461f78ae6345ca1.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/main-359cf9259ad67a06.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/framework-5429a50ba5373c56.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/pages/_app-f1f6d5684b7c625b.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/75fc9c18-af385d3bdb0a9ad1.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/152-39dfe41610587be7.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/chunks/pages/index-0cd460355d554a27.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/w3McG0lBB0i8_KK6uZMy_/_buildManifest.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/_next/static/w3McG0lBB0i8_KK6uZMy_/_ssgManifest.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3000/favicon.ico 404 (Not Found) favicon.ico:1

What can we do to fix things?

Specs

  • OS: Windows 11
  • Browser Brave latest
  • NodeJs - latest

Additional Context

Ideally, I want to run the page as Chevron does in Hosted mode. First, I wanted to run the app via node, and then I wanted to add a script to register it as a service.
I don't know much about frontend development, but hoped it could work that way, without additional software or running docker.

@LevYas
Copy link
Author

LevYas commented Feb 6, 2024

Gave it a try today, I executed the same command node .next/standalone/server.js and it worked. Magic!

@LevYas LevYas closed this as completed Feb 6, 2024
@LevYas
Copy link
Author

LevYas commented Feb 6, 2024

Hm, no, after building via yarn build it does not work anymore. Restarting terminal/browser/VS Code/computer does not help. Looks like some files are not copied to a location where they should be. Anyway, some assistance would be great.

@LevYas LevYas reopened this Feb 6, 2024
@excalith
Copy link
Owner

excalith commented Feb 7, 2024

Sorry mate, seems like I missed the notification for your report there. Will have a look at that soon. Cheers!

Related to #32

@excalith
Copy link
Owner

excalith commented Feb 7, 2024

Just realised I forgot to update redundant yarn export command on documentation. Since the project got more features, I had to use API calls and exporting a static page won't work. However, it is still possible to build and serve locally, just like development mode.

Wanted to quickly check out whats going on and turns out it works as intended on my end. Here is my logs with clean state:

yarn build
Skipped eslint warnings

 ✓ Linting and checking validity of types
   ▲ Next.js 14.0.4
   - Environments: .env

 ✓ Creating an optimized production build
 ✓ Compiled successfully
 ✓ Collecting page data
 ✓ Generating static pages (3/3)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

Route (pages)                              Size     First Load JS
┌ ○ /                                      45.1 kB         127 kB
├   └ css/607fb85db1ac148f.css             645 B
├   /_app                                  0 B            82.1 kB
├ ○ /404                                   181 B          82.3 kB
├ λ /api/getData                           0 B            82.1 kB
├ λ /api/getTheme                          0 B            82.1 kB
├ λ /api/loadSettings                      0 B            82.1 kB
└ λ /api/saveSettings                      0 B            82.1 kB
+ First Load JS shared by all              85.4 kB
  ├ chunks/framework-5429a50ba5373c56.js   45.2 kB
  ├ chunks/main-359cf9259ad67a06.js        31.7 kB
  ├ chunks/pages/_app-f1f6d5684b7c625b.js  3.46 kB
  ├ chunks/webpack-4461f78ae6345ca1.js     1.77 kB
  └ css/dec7afba07758c41.css               3.35 kB

○  (Static)   prerendered as static content
λ  (Dynamic)  server-rendered on demand using Node.js

Done in 16.33s.

yarn start

yarn run v1.22.21
$ next start
   ▲ Next.js 14.0.4
   - Local:        http://localhost:3000

 ⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.
 ✓ Ready in 500ms

On my end, ⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead. is a warning and seems like an issue on nextjs side since it generates the build files and reads from there itself.

After launching my localhost:3000 no errors / warnings thrown on my console. Just in case, can you try out 127.0.0.1:3000 as well?

Regarding to an easy self-hosting you mentioned, I suggest using something like PM2 or something similar to that to have control over background processes instead. I used PM2 for a few personal projects long before and it really is intuitive, like managing docker containers. After fixing this issue, I will try out this project with PM2 and update documentation with required steps to install and run.

@LevYas
Copy link
Author

LevYas commented Feb 7, 2024

Teşekkür ederim for looking into this!
Ha, I didn't notice that ⚠ "next start" does not work with "output: standalone" configuration. is actually a warning, it sounded like an error 😄.
Yes, with yarn start it works well.

On PM2 - I installed it successfully, but what arguments should I use?
pm2 start yarn -- start gives me [PM2][ERROR] Script not found: D:\_My\excalith-start-page\start
pm2 start yarn --interpreter bash --name "Start page" -- start gives the same error
pm2 start .\.next\standalone\server.js results in the error I mentioned in the first post (all 404).

I googled the error but looks like I need to create a deploy.json file and specify absolute paths. I'm not sure what paths should I use for yarn, and I'm feeling like I'm going too deep and there should be a simpler solution. Any advice?

@excalith
Copy link
Owner

excalith commented Feb 7, 2024

For PM2 I need to do some research, its been ages since I last used it :D Will check it when I find time, but if you find a way before me please let me know

@LevYas
Copy link
Author

LevYas commented Feb 7, 2024

I tried to run it with google, ChatGpt but with no luck. Apparently, PM2 does not work on windows, although some issues are marked as "closed". I tried some workarounds, and for me, this one worked:

  1. Create 'ecosystem.config.json`:
{
  "apps" : [
     {
        "name"          : "Start page",
        "script"        : "node_modules/next/dist/bin/next",
        "args"          : "start",
        "cwd"           : "D:/_My/excalith-start-page"
     }
  ]
}
  1. Start using pm2 start ecosystem.config.json

BUT, according to the docs, pm2 startup is not supported on Windows (see at the bottom of the page).

How do you think, is it possible to create a server script and register a service, like in Chevron? That project uses NPM instead of Yarn and some other dependencies, but maybe it's possible to adapt.

@excalith
Copy link
Owner

excalith commented Feb 8, 2024

Yesterday I managed to run it as a service just like you mentioned. I think it supports Windows startup, but not without any other modifications. Chevron uses a different package, haven't used it for such purposes before but will give it a try soon. Thanks for the support mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants