Skip to content
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

ReferenceError: exports is not defined #719

Open
danez opened this issue Mar 13, 2025 · 4 comments
Open

ReferenceError: exports is not defined #719

danez opened this issue Mar 13, 2025 · 4 comments

Comments

@danez
Copy link

danez commented Mar 13, 2025

Since #702 react-codemirror throws an error for me. I haven't had time to dig deeper, but it seems that the commons file is loaded, but because of "type:module" it is interpreted as ESM.

This is how I import in my source:

import { useCallback } from 'react';
import { useTheme } from 'next-themes';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { json } from '@codemirror/lang-json';
import { EditorView } from '@codemirror/view';

...
Image

ref: reactjs/react-docgen#976

@jaywcjlove
Copy link
Member

jaywcjlove commented Mar 13, 2025

@danez I see that it is needed in many places, especially in Vite projects. So are you suggesting that I should remove it or keep it? Removing it might affect certain use cases, but keeping it could cause issues like the one you encountered. What do you think?

@danez
Copy link
Author

danez commented Mar 13, 2025

Technically the type: module is wrong because not all files in the packed package are esm.

Maybe it would be better to remove the type:module again and instead use *.cjs and *.mjs extension for commonjs/esm. Then nodejs will do the correct thing.
Not sure though if it solves the vite problem.

Could also leave the type:module and only change commonjs to generate *.cjs files. I will try that tomorrow.

@MarcoPNS
Copy link

Have the same error. 4.23.8 runs perfectly but with 4.23.9 I get the "exports is not defined" error.

@jaywcjlove
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants