parcel-bundler / parcel

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

Scope hoisting bug #7308

Open kevinresol opened 2 years ago

kevinresol commented 2 years ago

When scope hoist is enabled, it breaks the app for some reason (to be investigated further)

🐛 bug report

Here are the steps to reproduce:

echo '{}' > package.json
yarn add -D parcel@2.0.1 http-server
yarn add @luma.gl/webgl@8.2.0
echo '<script src="index.js" type="module"></script>' > index.html
echo 'import * as Luma from "@luma.gl/webgl"' > index.js
echo 'console.log(Luma);' >> index.js
yarn parcel build index.html
yarn http-server dist &
open http://127.0.0.1:8080/index.html

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

N/A

🤔 Expected Behavior

The example code should print out the referenced object.

😯 Current Behavior

Screenshot 2021-11-16 at 15 52 26

💁 Possible Solution

Use --no-scope-hoist flag when building

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.0.1
Node 14.18.1
npm/Yarn yarn 1.22.17
Operating System macOS 12.0.1 (arm64)

(Edited: original post was accidentally submitted before finishing)

kevinresol commented 2 years ago

Reduced:

// index.js
console.log(require("./globals").global);

// globals.js
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.global = {foo: 'bar'};