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

CJS entry point can't be loaded in Node.js #649

Closed
inukshuk opened this issue Apr 28, 2023 · 4 comments · Fixed by #652 or #659
Closed

CJS entry point can't be loaded in Node.js #649

inukshuk opened this issue Apr 28, 2023 · 4 comments · Fixed by #652 or #659

Comments

@inukshuk
Copy link
Contributor

I might be doing something wrong, but I believe there is an issue with the current dual package setup. Type is set to module but the CJS entry point main points to "dist/tween.cjs.js". Despite the .cjs in there the Node.js loader still sees the final .js extension. Based on the nearest package.json it will therefore default to using the ESM loader for this file.

As a result, you can't currently require('@tweenjs/tween.js') in Node. Unless I'm missing something the .js extension should be dropped.

@trusktr
Copy link
Member

trusktr commented May 6, 2023

Thanks @inukshuk and @christjt for pointing these issues out!

@cc-steina
Copy link

Is there an alternative on how to add it in nodejs right now? I'm currently trying to add it to a Nextjs Application with typescript and I get this error:

ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and 'C:\git\PROJECT_DIRECTORY\node_modules\@tweenjs\tween.js\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

@inukshuk
Copy link
Contributor Author

Unfortunately the linked PR above doesn't address this issue. The CJS entry point needs to have a .cjs extension or the Node.js module loader will refuse to open it. The current .cjs.js one doesn't work.

@inukshuk
Copy link
Contributor Author

I submitted a PR for this above. It just renames the CJS entry point (which breaks the naming scheme but I don't think there's a way around making the Node.js loader accept a CJS in an ESM package).

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

Successfully merging a pull request may close this issue.

3 participants