Skip to content

Invalid UMD output when mixed outputs include CJS manualChunks: generated code contains illegal syntax like function vendor.xxx() #6296

@XGHeaven

Description

@XGHeaven

Rollup Version

4.59.0

Operating System (or Browser)

MacOS 14.6.1

Node Version (if applicable)

20.19.6

Link To Reproduction

https://stackblitz.com/edit/rollup-repro-iaxxfmyq

Expected Behaviour

UMD output should remain valid JavaScript regardless of other output entries.
Mixing umd and cjs outputs should not cause invalid identifier/function declarations in UMD codegen.

Config:

import nodeResolve from '@rollup/plugin-node-resolve';

export default {
  input: './src/main.js',
  output: [
    {
      name: 'main',
      file: './dist/index.js',
      format: 'umd',
    },
    {
      dir: './dist/',
      format: 'cjs',
      manualChunks: (id) => {
        if (/node_modules/.test(id)) {
          return 'vender';
        }
      },
    },
  ],
  plugins: [nodeResolve()],
};

Entry:

import { _ as type_of } from '@swc/helpers/esm/_get.js'

console.log(type_of)

Actual Behaviour

UMD output contains invalid syntax (function vender.xxx()) and cannot be parsed/executed.

Build output

// ...

        return object;
    }

    function vender._get(target, property, receiver) {
//                 ^ Error Here
        if (typeof Reflect !== "undefined" && Reflect.get) vender._get = Reflect.get;
        else {

// ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions