[英]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.