将文件移动到 Next.js 中的 src/pages 文件夹时,自定义 _app 和 _document 会被忽略

Max*_*cki 13 javascript reactjs next.js

The Next.js documentation states, that the directory src/pages is an alternative to /pages. However, my custom _app.tsx and _document.tsx files, get ignored when the pages folder is moved into src.

You can recreate this issue yourself, when creating an empty Next.js App, moving the pages folder into src and updating the import paths of the css files. The content of the index.tsx file will still be rendered, but modifications to the styles/globals.css, which is imported in the _app.tsx will have no effect.

It is impossible to have a pages folder inside of src and outside of src at the same time, therefore preventing me to use src/pages in any app which needs a modificaton to the _app.tsx or _document.tsx.

Am I missing an important part of the documentation or does this work as intended?

jul*_*ves 21

更改项目文件夹结构或添加新的_app/_document文件有时会导致缓存问题。

删除该.next文件夹并重新启动开发服务器,以确保 Next.js 完成的任何缓存不会妨碍。