-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Implement 'exports' field in package.json for the core & basics setup packages #692
Conversation
react-codemirror/core/package.json Lines 11 to 17 in c2437c7
@fatton139 modified |
Thanks for fixing that, no problems on our side. Cheers! |
This change now breaks my build and I always get this error:
|
@sotasan Could you provide an example to help us resolve this issue? |
Similar to @sotasan I get the following error when running in dev mode (for HMR):
and this error when running in production mode:
I'm using Typescript with Vite as my compiler. I get these errors as soon as I run |
The exports field directs node imports to the appropriate cjs or esm files depending on whether you're using cjs or esm. Based off of @sotasan and @rev-artian's error stacks it seems like an import from a cjs file has been incorrectly routed to the esm entrypoint when it should be going to the cjs entrypoint. Would you be able to confirm your configurations for your build & package.json are setup to use cjs not esm (it could be the other way too, you may want to be using esm but it's not configured to do so)? Thanks. |
@fatton139 I am using a normal Vite project with ESM configured in the package.json and I am importing it with the normal ESM syntax. |
@fatton139 My intent is to use esm. When I import ReactCodeMirror using package.json:
vite.config.ts:
|
@rev-artian I noticed you're using react-router as the build so I took a quick look and indeed your issue occurs. This seems to be an issue already raised remix-run/remix#9554 remix-run/remix#9070 and there are workarounds in the form of limiting your imports to @sotasan I set up a "normal" vite app using |
@fatton139 Sorry, I should have been more specific. This is not what you would call "normal". I am using SvelteKit (SPA) with the basic setup package, but everything should be bundled with normal Vite. Nevertheless I will try using the CJS file directly. |
I have now upgraded all my dependencies and with that, it seems to work. |
@fatton139 I hadn't seen the I had already tried |
As mentioned in #613 (comment), this same approach needs applying to themes/theme/package.json. |
Added exports field to the core (@uiw/react-codemirror) and basic setup (@uiw/codemirror-extensions-basic-setup) package.json so Node-like environments such as the test runners can utilise the esm outputs.
Context:
Our unit tests are failing with:
After some investigation, it looks like when this library is used in a Node environment all imports use the cjs output.
main
andmodule
are already defined and work for bundlers. However, Node doesn't have support formodule
and opts to look inexports
for entry points. Sinceexports
is not defined it falls back tomain
meaning Node will use the cjs outputs of this library. Normally this is fine, but the@codemirror
packages (i.e. @codemirror/language) in thepeerDependencies
do defineexports
so the esm outputs are used if we use any of those packages are used in our source code resulting in the error above.We're using
@codemirror/language
to construct an extension that gets passed intouseCodeMirror
, where cjs is used but the extension uses the esm output. This results in theinstanceof
checfailingil as the esm instance is not the cjs class.Likely related to #680 as they're using SSR which is potentially also in a Node-like environment.
We've manually modified the package.json locally to include the
export
field asserted our tests are passing and are using the correct esm output.