Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in scope-hoisting (between 2.9.3->2.12.0, includes nightly), $74eb372235a18b7a$exports is not defined #9972

Open
tbrockman opened this issue Oct 3, 2024 · 1 comment

Comments

@tbrockman
Copy link

tbrockman commented Oct 3, 2024

🐛 bug report

Now encountering the following error when importing @uiw/react-codemirror and using scope hoisting.

ReferenceError: $74eb372235a18b7a$exports is not defined
    <anonymous> editor.tsx:5
    React 7
    q scheduler.production.min.js:13
    X scheduler.production.min.js:14
    EventHandlerNonNull* scheduler.production.min.js:14
    g index.70a7763b.js:1
    <anonymous> index.js:4
    g index.70a7763b.js:1
    <anonymous> index.70a7763b.js:1
    g index.70a7763b.js:1
    <anonymous> React

With code like:

import { useCodeMirror } from "@uiw/react-codemirror"

export default function Editor() {
    const test = useCodeMirror({}) // $exports is not defined when scope-hoisted
}

Without being at all familiar with scope hoisting in Parcel, I would guess it might encounter an issue with @uiw/react-codemirrors simultaneous use of export * and export default. Previously this did not cause any issue at runtime (for example https://github.com/tbrockman/browser-extension-for-opentelemetry currently builds and works fine using a version of plasmo which leverages [email protected]).

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

Encountered through CLI tool (plasmo), which just invokes Parcel with some plugins specific to browser extensions (here shouldScopeHoist is set to true).

See https://github.com/tbrockman/parcel-scope-hoist-repro for reproducing the bug directly using parcel.

🤔 Expected Behavior

Scope-hoisting shouldn't remove code used at runtime.

😯 Current Behavior

Scope-hoisting is removing code which is used at runtime.

💁 Possible Solution

It appears that using a console.log (or presumably any function referencing the imported library?) like the following prevents the code from being pruned:

import * as cm from '@uiw/react-codemirror'
// and then later ...
console.log(cm) // this line is required (or some other reference to cm)
const test = cm.useCodeMirror({}) // strangely, this works

🔦 Context

💻 Code Sample

Repository for minimal reproduction of issue: https://github.com/tbrockman/parcel-scope-hoist-repro

🌍 Your Environment

Software Version(s)
Parcel
Node
npm/Yarn
Operating System
@tbrockman tbrockman changed the title Regression in scope-hoisting (between 2.9.3->2.12.0 and nightly), TypeError: (0 , $7DSBz.useCodeMirror) is not a function Regression in scope-hoisting (between 2.9.3->2.12.0, includes nightly), $74eb372235a18b7a$exports is not defined Oct 6, 2024
@tbrockman
Copy link
Author

tbrockman commented Oct 6, 2024

Updated the report with a link to a repo for reproducing the issue, and changed the bug description to reflect how the issue appears in that repo (rather than how the issue appears when using plasmo, which invokes parcel programmatically).

@mischnic encountered this when moving to nightly after the previous issue I had which ya helped me with (and confirmed it exists in 2.12.0 as well). Not sure if there's anything I can do to help fix this here or if this is something that's already on someones roadmap, but I'm open to looking into it depending on how long it might take a new contributor to work on it.

While I found a workaround for my use case by adding code to prevent it from being undefined after scope-hoisting, this was apart of a greater issue of upgrading plasmo to a newer version of parcel, which is blocked if it seems like it'll potentially lead to some subset of people having unexpected runtime errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant