Skip to content

Importing react signals in a node script fails with React 19 #637

@Artur-

Description

@Artur-

Environment

  • I am using @preact/signals-core
  • I am using @preact/signals
  • I am using @preact/signals-react

Describe the bug
It seems like node_modules/@preact/signals-react/runtime/dist/runtime.mjs in the distribution package cannot work with React 19 as it contains an eager import for __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED which has been removed in React 19. Seems to originate in https://github.com/preactjs/signals/blob/9022d4a770ce53c3e5c6a571f3ac5193ec2011b4/packages/react/runtime/src/auto.ts#L4C2-L4C71 and it happens even if you do not try to use auto tracking. Apparently everything is bundled into one file during release (?) and when running in Node, this one big module will be imported and fails because of the missing export from React.

To Reproduce

npm i @preact/signals-react && node -e 'import { useSignal } from "@preact/signals-react"; console.log(useSignal);'

Expected behavior
The import available only for React 18 is dynamically imported on demand

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions