Skip to content

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

@tbrockman

Description

@tbrockman

πŸ› 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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleInactive issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions