[英]Basic Next.js start ending in 404
我已经在 Next.js 上工作了一周,并决定在开发设置之外尝试它。 经过一些错误修复后,我设法构建它'让它开始'没有错误,但我最终得到: {"message":"Route GET:/ not found","error":"Not Found","statusCode":404}
打开 http://localhost:3000 时。
因此,在 docker 容器中进行了几次测试和一些尝试后,我尝试了最简单的设置,但结果相同:
npx create-next-app test
cd test
npm run dev //works when opening localhost:3000 so ^C to stop
npm run build
这给了:
> 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)
最后:
npm run start
这令人鼓舞:
> test@0.1.0 start
> next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
但不幸的是,打开 http://localhost:3000 会导致:
{"message":"Route GET:/ not found","error":"Not Found","statusCode":404}
有人能告诉我我错过了什么吗?
它看起来像我不能让它更简单,但它甚至没有工作..
谢谢大家
(可能有相同问题的人自行回答)
显然,npx(可执行文件)和 npm 运行的脚本之间存在细微差别。
事实上,在玩不同的指令时,我偶然发现了这个:
> npm run start
与 package.json :
{
...
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 8000",
"lint": "next lint"
},
...
}
不一样:
> npx next start -p 8000
因为 npm 将在端口 3000(不起作用)上打开服务器,在端口 8000(起作用)上打开 npx。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.