Next.js 页面在生产版本中以 404 结尾

Next.js pages end in 404 on production build

我构建了一个 next.js 应用程序。 这些页面在开发环境中工作正常,但是如果我尝试运行 生产构建只有 index.js 页面被正确加载,所有其他页面都以 404 结尾。

npm 运行 构建输出以下内容:

reating an optimized production build ...

Compiled successfully.

Warning: You have opted-out of Automatic Prerendering due to `getInitialProps` in `pages/_app`.
Read more: https://err.sh/next.js/opt-out-automatic-prerendering

Page                                    Size     Files  Packages
┌ σ /                                   66.8 kB      4        27
├   /_app                               17.9 kB      0        31
├   /_document
├   /_error                             397 B        0        27
├ σ /Products/[specificPage]/Dashboard  404 B        4        27
├ σ /Products/Overview                  95.1 kB      9        30
├ σ /Products/Roadmap                   475 B        4        27
├ σ /Strategy/Goals                     451 B        4        27
└ σ /Strategy/Metrics                   459 B        4        27

因此我假设页面构建正确。现在这让我很困惑。

在我的 index.js 页面上,我有一个 next/link 到 /strategy/goals 如果单击它会永远加载。如前所述,如果直接访问该页面,则显示 404。

编辑: 此外,控制台仅在 http://localhost:3000 上显示就绪 --> 不显示有关构建页面的任何日志,不确定这是否应该在生产中或仅在开发中发生。

TLDR: /页面应仅包含小写字母。

(我自己回答的)

问题是文件夹名称和文件(例如/Product/Overview)大写,这在测试中没有问题,因为 next 直接路由,大小写也没有问题。

执行构建版本,生产环境的文件系统接管路由。某些操作系统(对我来说是 macOS)区分大小写,并且由于找不到页面而无法正确路由。

已通过小写 /pages 目录中的所有内容修复。