错误 找不到"页面"目录。请在项目根目录下创建一个"



以前我的项目设置是

public
.next
src
pages
components
assets
next.config.js

这工作正常,但我将结构更改为以下

public
src
client
next.config.js
jsconfig.json
pages
components
assets
server
index.js

现在这个不起作用。我在页面directory. Please create one under the project root收到错误Couldn't find a

这是我更新的next.config.js

const withPlugins = require("next-compose-plugins");
const optimizedImages = require("next-optimized-images");
const withPWA = require("next-pwa");
module.exports = withPlugins(
[optimizedImages],
[
withPWA({
pwa: {
dest: "public",
},
}),
],
{
distDir: '../../dist/client',
}
);

用于绝对导入(从"组件/按钮"导入按钮(

jsconfig.json

{
"compilerOptions": {
"baseUrl": "client/"
}
}

包.json

"scripts": {
"dev:client": "nextjs src/client",
"dev:server": "node src/server --out-dir dist/server --source-maps --watch",
"dev": "dotenv -e .env.development yarn dev:client & yarn dev:server",
"build": "yarn build:client && yarn build:server",
"build:client": "dotenv -e .env.production next build src/client",
"build:server": "node src/server --out-dir dist/server --source-maps",
"build:staging": "yarn build:staging:client && yarn build:server",
"build:staging:client": "dotenv -e .env.staging next build src/client",
"start": "next start",
},

.babelrc

{
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
],
"presets": [
"next/babel"
]
}

根据官方的NextJs文档页面文件夹可以在src文件夹内移动。但是像next.config.js和tsconfig.json这样的配置文件应该在根目录中,将它们移动到src是行不通的。公共目录也是如此。

将 next.config.js 文件移动到根文件夹。

参考: https://nextjs.org/docs/advanced-features/src-directory

我设法在Windows系统上遇到同样的错误,其中我的页面文件夹称为"页面"(大写P(。将其重命名为小写 P 修复了它。

最新更新