-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
π 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> ReactWith 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 parcel@2.9.3).
π 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 |