Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded on use manualChunks #2906

Closed
6 tasks done
g4rcez opened this issue Apr 8, 2021 · 2 comments · Fixed by #2940
Closed
6 tasks done

Maximum call stack size exceeded on use manualChunks #2906

g4rcez opened this issue Apr 8, 2021 · 2 comments · Fixed by #2940

Comments

@g4rcez
Copy link

g4rcez commented Apr 8, 2021

Describe the bug

When I using manualChunks to split node_modules dependencies into chunk files, the error [vite:build-html] Maximum call stack size exceeded appears.

This bug only occurs when the manualChunks option is present in build.rollupOptions with the settings presented in this vite.config.ts:

import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import reactRefresh from "@vitejs/plugin-react-refresh";
import fs from "fs";
import { join } from "path";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default ({ mode }) =>
  defineConfig({
    plugins: [reactRefresh()],
    base: mode === "development" ? undefined : "/app/0.0.1/",
    json: {
      stringify: true,
    },
    build: {
      rollupOptions: {
        plugins: [commonjs(), resolve(), babel({ babelHelpers: "bundled" })],
        output: {
          assetFileNames: "assets/[name][extname]",
          entryFileNames: (a) =>
            a.name.endsWith(".js") ? a.name : "[name].js",
          chunkFileNames: (a) =>
            a.name.endsWith(".js") ? a.name : "[name].js",
          manualChunks(id) {
            if (id.includes("node_modules")) {
              const [, module] = /node_modules\/(@?[a-z0-9-]+?[a-z0-9-]+)/.exec(
                id
              );
              const path = join(
                process.cwd(),
                "node_modules",
                module,
                "package.json"
              );
              if (fs.existsSync(path)) {
                try {
                  const packageJson = require(path);
                  const version = packageJson.version;
                  console.log(module, version);
                  return `@vendor/${module}_${version}.js`;
                } catch (error) {}
              }
            }
          },
        },
      },
    },
  });

Reproduction

  1. Clone https://github.com/g4rcez/vite-testing
  2. yarn
  3. yarn build

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Linux 5.9 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 4.51 GB / 15.43 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Firefox: 87.0
  npmPackages:
    vite: 2.1.5 => 2.1.5 

Used package manager: yarn

Logs

  vite:config bundled config file loaded in 165ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'react-refresh',
  vite:config     'vite:dynamic-import-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'commonjs',
  vite:config     'node-resolve',
  vite:config     'babel',
  vite:config     'vite:import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter'
  vite:config   ],
  vite:config   base: '/app/0.0.1/',
  vite:config   json: { stringify: true },
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge18', 'firefox60', 'chrome61', 'safari11' ],
  vite:config     polyfillDynamicImport: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { plugins: [Array], output: [Object] },
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     cleanCssOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     brotliSize: true,
  vite:config     chunkSizeWarningLimit: 500
  vite:config   },
  vite:config   configFile: '/home/g4rcez/Documents/vite-tsx/vite.config.ts',
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/home/g4rcez/Documents/vite-tsx',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object] ] },
  vite:config   publicDir: '/home/g4rcez/Documents/vite-tsx/public',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   optimizeCacheDir: '/home/g4rcez/Documents/vite-tsx/node_modules/.vite',
  vite:config   server: {},
  vite:config   env: {
  vite:config     BASE_URL: '/app/0.0.1/',
  vite:config     MODE: 'production',
  vite:config     DEV: false,
  vite:config     PROD: true
  vite:config   },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen]
  vite:config   },
  vite:config   createResolver: [Function: createResolver]
  vite:config } +6ms
vite v2.1.5 building for production...
 47 modules transformed.
react 17.0.2
react-dom 17.0.2
react-router-dom 5.2.0
react 17.0.2
react 17.0.2
react-dom 17.0.2
react-dom 17.0.2
react-router 5.2.0
history 4.10.1
prop-types 15.7.2
tiny-warning 1.0.3
tiny-invariant 1.1.0
object-assign 4.1.1
object-assign 4.1.1
scheduler 0.20.2
react 17.0.2
scheduler 0.20.2
mini-create-react-context 0.4.1
path-to-regexp 1.8.0
react-is 16.13.1
hoist-non-react-statics 3.3.2
prop-types 15.7.2
prop-types 15.7.2
resolve-pathname 3.0.0
value-equal 1.0.1
prop-types 15.7.2
prop-types 15.7.2
scheduler 0.20.2
scheduler 0.20.2
react-is 16.13.1
react-is 16.13.1
react-is 16.13.1
isarray 0.0.1
isarray 0.0.1
Generated an empty chunk: "@vendor/tiny-warning_1.0.3.js"
Generated an empty chunk: "@vendor/value-equal_1.0.1.js"
rendering chunks (20)...[vite:build-html] Maximum call stack size exceeded
error during build:
RangeError: Maximum call stack size exceeded
    at getCssTagsForChunk (/home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24152:40)
    at /home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24157:38
    at Array.forEach (<anonymous>)
    at getCssTagsForChunk (/home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24154:31)
    at /home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24157:38
    at Array.forEach (<anonymous>)
    at getCssTagsForChunk (/home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24154:31)
    at /home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24157:38
    at Array.forEach (<anonymous>)
    at getCssTagsForChunk (/home/g4rcez/Documents/vite-tsx/node_modules/vite/dist/node/chunks/dep-66eb515d.js:24154:31)

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
@sylcastaing
Copy link

Same error with more simple example.

manualChunks(id) {
  if (id.includes('semantic-ui')) {
    return 'semantic';
  } else if (id.includes('react-dom')) {
    return 'react';
  } else if (id.includes('node_modules')) {
    return 'vendor';
  }
},

If I remove one condition it's working.

@g4rcez
Copy link
Author

g4rcez commented Apr 9, 2021

If you try to split the dependencies with more than two modules, the same error always occurs

psaren added a commit to psaren/vite that referenced this issue Apr 10, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 11, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 13, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 13, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 13, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 14, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 14, 2021
psaren added a commit to psaren/vite that referenced this issue Apr 14, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants