question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm run build under nginx routing not working.

See original GitHub issue

I have approx 6 routes in a spa app. svelte-routing works perfectly with npm run dev.

if I build with npm run build and then run the app inside an nginx docker container, routes do not work. eg. ‘http://localhost:8080/products’ and press enter … “404 Not Found … nginx/1.17.7”

does anyone have any ideas on where to look for the problem?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MrSrsencommented, Jul 17, 2020

If I understand it correctly npm run build do not generate physical files in /public so nginx is trying to find non existing physical file and fails.

If you want your SPA to work properly you must config your nginx to redirect all calls (with path intact) to index.html file. This fixed the same issues with exported Svelte/Sapper application that I was working on.

I don’t know how to configure nginx but for Apache my working .htaccess is:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html?q=$1 [L,QSA]

Or use hash routing.

0reactions
kevin4dhdcommented, Sep 30, 2022

any example only nginx?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Router routes not working on nginx create-react-app
This fixes the React Router issues where you allow nginx to route traffic coming on different endpoints, directly to you React Application.
Read more >
Nginx in not recognizing nested routes(react-router) after the ...
In locally react-router is working fine and i had not gotten any issue ... RUN npm run build # => Run container FROM...
Read more >
Routes not working after npm build - Vue Forum
Today I tried npm run build. for production setup. The npm run build completed successfully and created dist folder within my vue.js app...
Read more >
How To Deploy a React Application with Nginx on Ubuntu 20.04
To create a production build, use npm build. Stop the project by entering either CTRL+C or ⌘+C in a terminal.
Read more >
Using NGINX to serve React Application (Static vs Reverse ...
We will keep our focus on the setup of Nginx with React . ... We run them using our node server that is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found