parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.52k stars 2.26k forks source link

Cannot load minified ES6 module #8629

Open thdoan opened 2 years ago

thdoan commented 2 years ago

🐛 bug report

Parcel fails to import the ES6 version of tweenjs.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "devDependencies": {
    "@parcel/packager-raw-url": "^2.8.0",
    "@parcel/transformer-webmanifest": "^2.8.0",
    "parcel": "^2.8.0",
    "process": "^0.11.10"
  },
  "dependencies": {
    "three": "^0.146.0"
  }
}

🤔 Expected Behavior

The TWEEN object should be present.

😯 Current Behavior

The TWEEN object is undefined.

💁 Possible Solution

🔦 Context

💻 Code Sample

Steps to reproduce:

  1. Unzip test.zip
  2. npm install three
  3. yarn parcel test.html

🌍 Your Environment

Software Version(s)
Parcel 2.8.0
Node 16.14.2
npm/Yarn yarn 1.22.17
Operating System Windows 10 (using Git Bash)
mischnic commented 2 years ago

Reproduction:

// a.js
import { TWEEN } from "./b.js";
console.log(TWEEN);

// b.js
var TWEEN = "something";
(function (t) {
    if ("undefined" != typeof module && "object" == typeof exports) {
        module.exports = TWEEN; // Parcel takes this branch
    } else if (t !== undefined) {
        t.TWEEN = TWEEN;
    }
})(this);
export { TWEEN };

But there's really not a lot we can do here because of the combination of ESM and CJS in the same file.