-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Native ESM import problem 'with use-sync-external-store' #2191
Comments
This will be fixed by facebook/react#25231. It's a bit of a pointing fingers thing. We're not doing anything incorrect, uSES is doing things technically wrong. It sounds like there could be some movement soon, but I'll leave this open to fix on our end for now. |
We might get away with keeping a |
Thanks! Out of curiosity, in which environments is the CommonJS Speaking only for Node.js |
I might actually have gotten it the wrong way round, my bad. ESM can import CJS, but still needs the I'm still not convinced that the "default" syntax suggested here would work in all cases, though :/ Is this really an error message and not just a warning? The wording ("may") weirdly sounds like it isn't even sure if the original statement might even work or not. |
@phryneas Yeah I'm kind of confused too, because right now if you have a file like import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'
console.log(useSyncExternalStoreWithSelector) You can run it by: node someFile.mjs and you will get: [Function: useSyncExternalStoreWithSelector] which is fine. You can also have this in a const { useSyncExternalStoreWithSelector } = require('use-sync-external-store/with-selector.js')
console.log(useSyncExternalStoreWithSelector) and you will again get the same thing so I'm not sure exactly what the issue is. |
@aryaemami59 oh, you're right the import works fine with the latest Node.s loader. For some reason, I can only reproduce this when I import @phryneas it's thrown as a |
OK I think I understand a little bit better why this is happening. As described here the Node.js loader will always import the CJS In this particular case the static analysis of So yes, there's definitely not an issue here, it's an issue with the ESM loader in Electron. Sorry for the noise! But one thing to take away is that if you encounter this vague SyntaxError it likely means that the static analysis failed. |
Just leaving this here in case somebody hits a similar issue with the ESM loader in Electron: the issue happens if you use a dynamic import after the page has loaded and your CSP prohibits 'unsafe-eval'. |
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
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, usingreact-redux
using native ESM loader currently produces an error like this: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?
The text was updated successfully, but these errors were encountered: