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

Cannot load Luxon - "Cannot access uninitialized variable." #1961

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

Cannot load Luxon - "Cannot access uninitialized variable." #1961

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

Comments

@JL102
Copy link
Contributor

JL102 commented Feb 1, 2023

What version of Bun is running?

0.5.3

What platform is your computer?

Tested on Linux 5.19.0-29-generic x86_64 x86_64 and Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

  1. bun install luxon
  2. edit test.mjs:
import { DateTime } from 'luxon';
  1. Run bun test.mjs

What is the expected behavior?

The expected behavior would be to have the import succeed and have the program exit immediately.
Running node test.mjs does this.

What do you see instead?

drak@JBOOK:~/test$ bun test.mjs
1 | import SystemZone from "./zones/systemZone.js";
2 | import IANAZone from "./zones/IANAZone.js";
3 | import Locale from "./impl/locale.js";
   ^
ReferenceError: Cannot access uninitialized variable.
      at /home/drak/test/node_modules/luxon/src/settings.js:3:0

Additional information

To troubleshoot, I tried doing an import from luxon's source code instead of from node_modules:

  1. git clone https://github.com/moment/luxon.git
  2. cd luxon
  3. git checkout b1fee58b8719176ff55eb9709084102f6baeb77a (this is the commit associated with their most recent release)
  4. edited test.mjs:
import { DateTime } from './luxon/src/luxon';
  1. bun test.mjs
    and strangely, it works fine.

Maybe related to #453?

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

This is a CommonJS/ESM interop issue. Transpiler is expecting the file to be CJS but it is actually ESM and the wrapper is being before other files are loaded

@JL102
Copy link
Contributor Author

JL102 commented Feb 1, 2023

Why would it expect it to be CJS when loading via node_modules (import { DateTime } from 'luxon';) but not when loading via the file path? (import { DateTime } from './luxon/src/luxon';)

It seems like Bun is being instructed to go to luxon's src folder because of how luxon's package.json is set up, but it seems to be explicitly a module, i.e. ESM...? https://github.com/moment/luxon/blob/master/package.json#L61

EDIT: Doing import { DateTime } from './luxon'; also runs fine without errors (i assume that in this case, Bun is still reading the package.json so it knows to go into the src folder, etc.)

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