I've been working for a week on Next.js and decided to try it outside of the dev setup. After some bug fixing I've managed to build it 'make it start' without errors but I ended up on :
{"message":"Route GET:/ not found","error":"Not Found","statusCode":404}
when opening http://localhost:3000.
So after few tests and some tries within a docker container I tried the simplest of setups which resulted in the same matter:
npx create-next-app test
cd test
npm run dev //works when opening localhost:3000 so ^C to stop
npm run build
which give :
> test@0.1.0 build
> next build
info - Checking validity of types
info - Creating an optimized production build
info - Compiled successfully
info - Collecting page data
info - Generating static pages (3/3)
info - Finalizing page optimization
Page Size First Load JS
┌ ○ / 6.25 kB 81.2 kB
├ └ css/149b18973e5508c7.css 655 B
├ /_app 0 B 74.9 kB
├ ○ /404 193 B 75.1 kB
└ λ /api/hello 0 B 74.9 kB
+ First Load JS shared by all 74.9 kB
├ chunks/framework-1f10003e17636e37.js 45 kB
├ chunks/main-fc7d2f0e2098927e.js 28.7 kB
├ chunks/pages/_app-69da446bea935969.js 493 B
├ chunks/webpack-69bfa6990bb9e155.js 769 B
└ css/27d177a30947857b.css 194 B
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
and finally:
npm run start
which give an encouraging :
> test@0.1.0 start
> next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
But unfortunately opening http://localhost:3000 results in :
{"message":"Route GET:/ not found","error":"Not Found","statusCode":404}
Can someone tell me what am I missing ?
It seams like I cannot make it simpler but it is not even working..
Thanks all
(Self answer for those who could have the same issue)
Apparently there is a subtle difference between npx (executable) and scripts runned by npm.
Indeed, playing with different instructions I stumbled across this:
> npm run start
with package.json :
{
...
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 8000",
"lint": "next lint"
},
...
}
is not the same as :
> npx next start -p 8000
Because npm will open a server on port 3000 (that does not work) and npx on port 8000 (that does work).