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

Bun does not work with commonjs as expected #1968

Closed
gera2ld opened this issue Feb 1, 2023 · 2 comments · Fixed by #2312
Closed

Bun does not work with commonjs as expected #1968

gera2ld opened this issue Feb 1, 2023 · 2 comments · Fixed by #2312
Labels
bug Something isn't working

Comments

@gera2ld
Copy link

gera2ld commented Feb 1, 2023

What version of Bun is running?

0.5.4

What platform is your computer?

Darwin 21.6.0 x86_64 i386

What steps can reproduce the bug?

In a new directory, run the commands below:

$ bun init -y
$ bun add encoding-japanese

Change the content of index.ts to require('encoding-japanese').
Then run bun run index.ts.

What is the expected behavior?

No error.

What do you see instead?

An error occurred.

1 | exports.UTF8_TO_JIS_TABLE = require('./utf8-to-jis-table');
2 | exports.UTF8_TO_JISX0212_TABLE = require('./utf8-to-jisx0212-table');
3 | exports.JIS_TO_UTF8_TABLE = require('./jis-to-utf8-table');
           ^
TypeError: null is not an object (evaluating 'l[U]')
      at .../node_modules/encoding-japanese/src/encoding-table.js:3:8
      at .../node_modules/encoding-japanese/src/config.js:2:4
      at .../node_modules/encoding-japanese/src/index.js:1:4
      at .../index.ts:1:0

Additional information

No response

@gera2ld gera2ld added the bug Something isn't working label Feb 1, 2023
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Feb 1, 2023

This needs to be documented somewhere but currently if you use CommonJS in your own app code it won't work unless you use require or .cjs, .cts etc

It will work if it's a dependency or node_modules

You can always import ESM though

@gera2ld
Copy link
Author

gera2ld commented Feb 1, 2023

Actually I got an issue from node_modules and then found this when I tried to debug it.

I updated my case, sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants