前端使用nextjs ,在开发环境编译相当慢 ,比便秘还让人痛苦 ,你们有什么办法 #5230

Closed
opened 2026-02-21 18:09:59 -05:00 by yindo · 2 comments
Owner

Originally created by @yu99233 on GitHub (Aug 26, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

前端使用nextjs ,在开发环境编译相当慢 ,比便秘还让人痛苦 ,你们有什么办法解决开发环境相当慢的问题 ,编译至少要等10分钟以上才能出现页面

Originally created by @yu99233 on GitHub (Aug 26, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes 前端使用nextjs ,在开发环境编译相当慢 ,比便秘还让人痛苦 ,你们有什么办法解决开发环境相当慢的问题 ,编译至少要等10分钟以上才能出现页面
yindo closed this issue 2026-02-21 18:09:59 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 26, 2024):

Hello, @yu99233! I'm here to help you with any bugs, questions, or contributions you may have. Let's work together to solve the issue you're experiencing.

To resolve the extremely slow compilation issue in the development environment when using Next.js, you can try the following steps:

  1. Disable the codeInspectorPlugin in development mode: This plugin might be causing the slowdown. You can conditionally add it only in production mode.

  2. Optimize ESLint configuration: Ensure ESLint is not running during development as it can slow down the build.

  3. Update tsconfig.json for better performance: Ensure that your TypeScript configuration is optimized for development.

Here is the modified next.config.js:

const { codeInspectorPlugin } = require('code-inspector-plugin')
const withMDX = require('@next/mdx')({
  extension: /\.mdx?$/,
  options: {
    remarkPlugins: [],
    rehypePlugins: [],
  },
})

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { dev, isServer }) => {
    if (!dev) {
      config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' }))
    }
    return config
  },
  productionBrowserSourceMaps: false,
  pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
  experimental: {},
  eslint: {
    ignoreDuringBuilds: true,
    dirs: ['app', 'bin', 'config', 'context', 'hooks', 'i18n', 'models', 'service', 'test', 'types', 'utils'],
  },
  typescript: {
    ignoreBuildErrors: true,
  },
  reactStrictMode: true,
  async redirects() {
    return [
      {
        source: '/',
        destination: '/apps',
        permanent: false,
      },
    ]
  },
  output: 'standalone',
}

module.exports = withMDX(nextConfig)

And here is the tsconfig.json for reference:

{
  "compilerOptions": {
    "target": "es2015",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": [
        "./*"
      ]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "app/components/develop/Prose.jsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

By making these changes, you should see an improvement in the compilation speed during development [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 26, 2024): <!-- Greeting --> Hello, @yu99233! I'm here to help you with any bugs, questions, or contributions you may have. Let's work together to solve the issue you're experiencing. <!-- Answer --> To resolve the extremely slow compilation issue in the development environment when using Next.js, you can try the following steps: 1. **Disable the `codeInspectorPlugin` in development mode**: This plugin might be causing the slowdown. You can conditionally add it only in production mode. 2. **Optimize ESLint configuration**: Ensure ESLint is not running during development as it can slow down the build. 3. **Update `tsconfig.json` for better performance**: Ensure that your TypeScript configuration is optimized for development. Here is the modified `next.config.js`: ```js const { codeInspectorPlugin } = require('code-inspector-plugin') const withMDX = require('@next/mdx')({ extension: /\.mdx?$/, options: { remarkPlugins: [], rehypePlugins: [], }, }) /** @type {import('next').NextConfig} */ const nextConfig = { webpack: (config, { dev, isServer }) => { if (!dev) { config.plugins.push(codeInspectorPlugin({ bundler: 'webpack' })) } return config }, productionBrowserSourceMaps: false, pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'], experimental: {}, eslint: { ignoreDuringBuilds: true, dirs: ['app', 'bin', 'config', 'context', 'hooks', 'i18n', 'models', 'service', 'test', 'types', 'utils'], }, typescript: { ignoreBuildErrors: true, }, reactStrictMode: true, async redirects() { return [ { source: '/', destination: '/apps', permanent: false, }, ] }, output: 'standalone', } module.exports = withMDX(nextConfig) ``` And here is the `tsconfig.json` for reference: ```json { "compilerOptions": { "target": "es2015", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [ { "name": "next" } ], "paths": { "@/*": [ "./*" ] } }, "include": [ "next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/components/develop/Prose.jsx" ], "exclude": [ "node_modules" ] } ``` By making these changes, you should see an improvement in the compilation speed during development <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/next.config.js)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/tsconfig.json)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@nadirvishun commented on GitHub (Nov 26, 2024):

I'm also having this problem and I'm crushed!

@nadirvishun commented on GitHub (Nov 26, 2024): I'm also having this problem and I'm crushed!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5230