javascript - 错误找不到 `pages` 目录。请在项目根目录下创建一个”

标签 javascript reactjs next.js

以前我的项目设置是

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

这工作正常,但我将结构更改为以下
public
src
   client
    next.config.js
    jsconfig.json
    pages
    components
    assets
   server
    index.js

现在这个不工作了。我收到错误 Couldn't find adirectory. Please create one under the project root
这是我更新的 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 是行不通的。公共(public)目录也是如此。

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

引用:https://nextjs.org/docs/advanced-features/src-directory

关于javascript - 错误找不到 `pages` 目录。请在项目根目录下创建一个”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61903950/

相关文章:

javascript - 从 javascript 形式解析到数据库

javascript - 让 Dojo 1.9 处理关键事件

css - 创建响应式加载器内容

next.js - Nextjs中动态路由的区别

javascript - 在 NextJS 中将 CSS 模块类声明为变量

javascript - OSX 上 Chrome 上的键码消歧

javascript - 等待状态改变以对 redux 使用react

reactjs - asp.net core 2.1 Webpack 4 React 无法正常启动

next.js - 您应该如何使用 getServerSideProps 在路由转换时获取客户端数据?

javascript - D3中是否需要退出选择?