vite: Vite-6.0.7 appears to transpile `case` statements incorrectly

Describe the bug

Taking the base example from StackBlitz, importing js2pdf-2.5.1 and attempting to build fails with an error about unexpected case.

Output fails with the following:

Error during build:
[vite:esbuild-transpile] Transform failed with 1 error:
assets/index-!~{001}~.js:960:38152: ERROR: Unexpected "case"

Someone else posted about it today that I only just found and identified that it was the transpilation turning case false: in casefalse: and sure enough the minified version in the error message includes:

...
switch(R){case 0:casefalse:case"fill":D=0;break;case 1:
...

Reproduction

https://github.com/ikelos/minimal-vite-jspdf-issue

Steps to reproduce

Run npm install folllowed by npm run build.

System Info

System:
    OS: Linux 6.12 Gentoo Linux
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 5.91 GB / 15.35 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.10.0 - /usr/bin/node
    npm: 10.9.0 - /usr/bin/npm
  npmPackages:
    vite: ^6.0.7 => 6.0.7

Used Package Manager

npm

Logs

Click to expand!

Full output gets marked as too long (66535 bytes) so also included as an attachment: vite-build-debug-log.txt

2025-01-06T18:08:46.997Z vite:config no config file found.
2025-01-06T18:08:47.014Z vite:config using resolved config: {
  root: '/home/mike/tmp/minimal',
  base: '/',
  mode: 'production',
  configFile: undefined,
  logLevel: undefined,
  clearScreen: undefined,
  build: {
    target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
    polyfillModulePreload: true,
    modulePreload: { polyfill: true },
    outDir: 'dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    sourcemap: false,
    terserOptions: {},
    rollupOptions: {},
    commonjsOptions: { include: [ /node_modules/ ], extensions: [ '.js', '.cjs' ] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [ /node_modules/ ] },
    write: true,
    emptyOutDir: null,
    copyPublicDir: true,
    manifest: false,
    lib: false,
    ssrManifest: false,
    ssrEmitAssets: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    cssCodeSplit: true,
    minify: 'esbuild',
    ssr: false,
    emitAssets: true,
    createEnvironment: [Function: createEnvironment],
    cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
    cssMinify: true
  },
  environments: {
    client: {
      define: undefined,
      resolve: {
        externalConditions: [ 'node' ],
        extensions: [ '.mjs', '.js', '.ts', '.jsx', '.tsx', '.json' ],
        dedupe: [],
        noExternal: [],
        external: [],
        preserveSymlinks: false,
        alias: [
          {
            find: /^\/?@vite\/env/,
            replacement: '/@fs/home/mike/tmp/minimal/node_modules/vite/dist/client/env.mjs'
          },
          {
            find: /^\/?@vite\/client/,
            replacement: '/@fs/home/mike/tmp/minimal/node_modules/vite/dist/client/client.mjs'
          }
        ],
        mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
        conditions: [ 'module', 'browser', 'development|production' ],
        enableBuiltinNoExternalCheck: false
      },
      keepProcessEnv: false,
      consumer: 'client',
      optimizeDeps: {
        include: [],
        exclude: [],
        needsInterop: [],
        extensions: [],
        disabled: undefined,
        holdUntilCrawlEnd: true,
        force: false,
        noDiscovery: false,
        esbuildOptions: { preserveSymlinks: false }
      },
      dev: {
        warmup: [],
        sourcemap: { js: true },
        sourcemapIgnoreList: [Function: isInNodeModules$1],
        preTransformRequests: true,
        createEnvironment: [Function: defaultCreateClientDevEnvironment],
        recoverable: true,
        moduleRunnerTransform: false
      },
      build: {
        target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
        polyfillModulePreload: true,
        modulePreload: { polyfill: true },
        outDir: 'dist',
        assetsDir: 'assets',
        assetsInlineLimit: 4096,
        sourcemap: false,
        terserOptions: {},
        rollupOptions: {},
        commonjsOptions: { include: [ /node_modules/ ], extensions: [ '.js', '.cjs' ] },
        dynamicImportVarsOptions: { warnOnError: true, exclude: [ /node_modules/ ] },
        write: true,
        emptyOutDir: null,
        copyPublicDir: true,
        manifest: false,
        lib: false,
        ssrManifest: false,
        ssrEmitAssets: false,
        reportCompressedSize: true,
        chunkSizeWarningLimit: 500,
        watch: null,
        cssCodeSplit: true,
        minify: 'esbuild',
        ssr: false,
        emitAssets: true,
        createEnvironment: [Function: createEnvironment],
        cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
        cssMinify: true
      }
    }
  },
  resolve: {
    externalConditions: [ 'node' ],
    extensions: [ '.mjs', '.js', '.ts', '.jsx', '.tsx', '.json' ],
    dedupe: [],
    noExternal: [],
    external: [],
    preserveSymlinks: false,
    alias: [
      {
        find: /^\/?@vite\/env/,
        replacement: '/@fs/home/mike/tmp/minimal/node_modules/vite/dist/client/env.mjs'
      },
      {
        find: /^\/?@vite\/client/,
        replacement: '/@fs/home/mike/tmp/minimal/node_modules/vite/dist/client/client.mjs'
      }
    ],
    mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
    conditions: [ 'module', 'node', 'development|production' ],
    enableBuiltinNoExternalCheck: false
  },
  configFileDependencies: [],
  inlineConfig: {
    root: undefined,
    base: undefined,
    mode: undefined,
    configFile: undefined,
    logLevel: undefined,
    clearScreen: undefined,
    build: {},
    environments: {
      client: {
        define: undefined,
        resolve: undefined,
        dev: {},
        build: {},
        optimizeDeps: undefined
      }
    },
    resolve: { conditions: undefined, mainFields: undefined }
  },
  decodedBase: '/',
  rawBase: '/',
  publicDir: '/home/mike/tmp/minimal/public',
  cacheDir: '/home/mike/tmp/minimal/node_modules/.vite',
  command: 'build',
  isWorker: false,
  mainConfig: null,
  bundleChain: [],
  isProduction: true,
  plugins: [
    'vite:build-metadata',
    'vite:watch-package-data',
    'vite:pre-alias',
    'alias',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm-helper',
    'vite:worker',
    'vite:asset',
    'vite:wasm-fallback',
    'vite:define',
    'vite:css-post',
    'vite:build-html',
    'vite:worker-import-meta-url',
    'vite:asset-import-meta-url',
    'vite:force-systemjs-wrap-complete',
    'commonjs',
    'vite:data-uri',
    'vite:rollup-options-plugins',
    'vite:dynamic-import-vars',
    'vite:import-glob',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:terser',
    'vite:manifest',
    'vite:ssr-manifest',
    'vite:reporter',
    'vite:load-fallback'
  ],
  css: {
    transformer: 'postcss',
    preprocessorMaxWorkers: 0,
    devSourcemap: false,
    lightningcss: undefined
  },
  json: { namedExports: true, stringify: 'auto' },
  esbuild: { jsxDev: false },
  server: {
    port: 5173,
    strictPort: false,
    host: undefined,
    https: undefined,
    open: false,
    proxy: undefined,
    cors: true,
    headers: {},
    warmup: { clientFiles: [], ssrFiles: [] },
    middlewareMode: false,
    fs: {
      strict: true,
      deny: [ '.env', '.env.*', '*.{crt,pem}', '**/.git/**' ],
      allow: [ '/home/mike/tmp/minimal' ]
    },
    preTransformRequests: true,
    perEnvironmentStartEndDuringDev: false,
    sourcemapIgnoreList: [Function: isInNodeModules$1]
  },
  builder: undefined,
  preview: {
    port: 4173,
    strictPort: false,
    host: undefined,
    https: undefined,
    open: false,
    proxy: undefined,
    cors: true,
    headers: {}
  },
  envDir: '/home/mike/tmp/minimal',
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(1) {
    'fnpd_/home/mike/tmp/minimal' => {
      dir: '/home/mike/tmp/minimal',
      data: {
        name: 'vite-starter',
        private: true,
        version: '0.0.0',
        type: 'module',
        scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview' },
        devDependencies: { vite: '^6.0.7' },
        dependencies: { jspdf: '^2.5.2' }
      },
      hasSideEffects: [Function: hasSideEffects],
      setResolvedCache: [Function: setResolvedCache],
      getResolvedCache: [Function: getResolvedCache]
    },
    set: [Function (anonymous)]
  },
  worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
  appType: 'spa',
  experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  future: undefined,
  ssr: {
    target: 'node',
    optimizeDeps: { esbuildOptions: { preserveSymlinks: false } },
    resolve: { conditions: undefined, externalConditions: undefined }
  },
  optimizeDeps: {
    include: [],
    exclude: [],
    needsInterop: [],
    extensions: [],
    disabled: undefined,
    holdUntilCrawlEnd: true,
    force: false,
    noDiscovery: false,
    esbuildOptions: { preserveSymlinks: false }
  },
  dev: {
    warmup: [],
    sourcemap: { js: true },
    sourcemapIgnoreList: [Function: isInNodeModules$1],
    preTransformRequests: false,
    createEnvironment: [Function: defaultCreateDevEnvironment],
    recoverable: false,
    moduleRunnerTransform: false
  },
  getSortedPlugins: [Function: getSortedPlugins],
  getSortedPluginHooks: [Function: getSortedPluginHooks],
  createResolver: [Function: createResolver],
  fsDenyGlob: [Function: arrayMatcher],
  safeModulePaths: Set(0) {}
}
vite v6.0.7 building for production...
transforming...
✓ 232 modules transformed.
2025-01-06T18:08:48.292Z vite:esbuild esbuild error with options used:  {
  sourcemap: true,
  sourcefile: 'assets/index-!~{001}~.js',
  charset: 'utf8',
  jsxDev: false,
  loader: 'js',
  target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  format: 'esm',
  supported: { 'dynamic-import': true, 'import-meta': true },
  minify: true,
  treeShaking: true,
  tsconfigRaw: { compilerOptions: { useDefineForClassFields: false } }
}
x Build failed in 1.27s
error during build:
[vite:esbuild-transpile] Transform failed with 1 error:
assets/index-!~{001}~.js:960:38152: ERROR: Unexpected "case"

Unexpected "case"
958|   * https://github.com/foliojs/pdfkit/blob/master/lib/security.js
...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^
961|  /**
962|   * @license

    at failureErrorWithLog (/home/mike/tmp/minimal/node_modules/esbuild/lib/main.js:1476:15)
    at /home/mike/tmp/minimal/node_modules/esbuild/lib/main.js:755:50
    at responseCallbacks.<computed> (/home/mike/tmp/minimal/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/home/mike/tmp/minimal/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/home/mike/tmp/minimal/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
    at Readable.push (node:internal/streams/readable:392:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 20 (1 by maintainers)

Most upvoted comments

@IrakliJani, you saved my night - thanks 😃

Edit: See: https://github.com/rollup/rollup/issues/5784 4.29.2 works for me. Only the last version seems to be broken.

I fixed this issue by downgrading Vite’s rollup dependency from version v4.30.0 to v4.23.0, and that resolved the issue for me. The bug is likely present between these versions. I have not tested any other rollup versions. Hope this helps temporarily

Closing as Rollup 4.30.1 fixes this

Rollup v4.30.1 has been released. For me, npm run build works normally now. This can be closed.

I found that my local node_modules didn’t update, and the packaging was fine, so I couldn’t repeat the problem, but when I re-downloaded node_modules, the problem arose, was it some dependency package that was secretly updating something? So is there any solution other than downgrading the vite version?

@775043997 Add dependency restrictions

For NPM:

"overrides": {
    "rollup": "4.29.2"
  },

For Yarn:

"resolutions": {
"rollup": "4.29.2"
}

@Cluster2a awesome! thanks for tracking it down

having the same issue with jspdf

✓ 11900 modules transformed.
rendering chunks...
x Build failed in 1m 3s
error during build:
[vite:esbuild-transpile] Transform failed with 1 error:
assets/index-!~{001}~.js:388450:38198: ERROR: Unexpected "case"
Unexpected "case"