Skip to content

Native ESM import problem 'with use-sync-external-store' #2191

Closed
@inukshuk

Description

@inukshuk

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: 18
  • ReactDOM: 18
  • Redux: 5.0.1
  • React Redux: 9.1.2

What is the current behavior?

The module 'use-sync-external-store' published at the moment (v1.2.2) is a CommonJS module. When importing a CommonJS module into an ESM module with import, e.g. using Node's ESM loader named imports will not work. Because of this, using react-redux using native ESM loader currently produces an error like this:

The requested module 'use-sync-external-store/with-selector.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'use-sync-external-store/with-selector.js';
const { useSyncExternalStoreWithSelector } = pkg;"

This is probably not an issue in most setups because the modules are loaded via some compiler/bundler but it's an issue when using Node's native module loader.

What is the expected behavior?

If the import here and probably (?) here could be changed to rely on the default export instead then the import should work.

Which browser and OS are affected by this issue?

Node.js

Did this work in previous versions of React Redux?

  • Yes

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