rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.62k stars 581 forks source link

[plugin-terser] Minified UMD with default terser options cannot be consumed from ES6 #1674

Open springcomp opened 7 months ago

springcomp commented 7 months ago

Expected Behavior

Run the following command:

npm run build
npm run exec:dev

This generates a dist/sayHi.umd.min.js minified UMD module that is consumed as a CommonJS module from apps/dev/main.js using the require() instruction.

This produces the following output:

[Function (anonymous)]
Hello, John!
Good bye, John!

I would expect the same output when consuming the module as a ECMAScript module using the import instruction.

Actual Behavior

Run the following command:

npm run build
npm run exec:build

This generates a dist/sayHi.umd.min.js minified UMD module that is consumed as an ECMAScript module from apps/build/main.js using the import instruction.

This produces the following output:

file:///home/projects/rollup-repro-id5i6z/apps/build/main.js:5
import { sayGoodbye, sayHi } from '../../dist/sayHi.umd.min.js';
         ^^^^^^^^^^
SyntaxError: The requested module '../../dist/sayHi.umd.min.js' does not provide an export named 'sayGoodbye'
    at ModuleJob._instantiate (https://rollupreproid5i6z-kjjj-8fvnx673.w-corp.staticblitz.com/blitz.a9c8a5a3.js:181:1509)
    at async ModuleJob.run (https://rollupreproid5i6z-kjjj-8fvnx673.w-corp.staticblitz.com/blitz.a9c8a5a3.js:181:2327)

Additional Information