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

Memoizee TypeError: Attempted to assign to readonly property #15682

Open
jakpop opened this issue Dec 10, 2024 · 0 comments
Open

Memoizee TypeError: Attempted to assign to readonly property #15682

jakpop opened this issue Dec 10, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@jakpop
Copy link

jakpop commented Dec 10, 2024

What version of Bun is running?

1.1.38+bf2f153f5

What platform is your computer?

Linux 6.8.0-48-generic x86_64 x86_64

What steps can reproduce the bug?

run bun file.ts or bun test in a project using memoizee package

What is the expected behavior?

successful run

What do you see instead?

Unhandled error between tests


12 | , nextTick = require("next-tick");
13 |
14 | var create = Object.create
15 | , supportedModes = primitiveSet("then", "then:finally", "done", "done:finally");
16 |
17 | require("../lib/registered-extensions").promise = function (mode, conf) {
^
TypeError: Attempted to assign to readonly property.
at /node_modules/memoizee/ext/promise.js:17:1
at /node_modules/memoizee/index.js:27:23

Additional information

Issue is discussed broadly here - medikoo/memoizee#144. In short, inside a project that uses memoizee it is not possible to test it using bun test.

Quoting @heimskr's response:

The specific issue in memoizee is due to how Bun determines whether a module imported via require is a CommonJS module or an ES module. Currently, if you require a .js file that either is empty or contains "use strict" (as is the case for lib/registered-extensions.js), Node will consider it a CommonJS module and Bun's heuristics will decide it's an ES module. This makes a difference because CommonJS modules imported via require aren't frozen or sealed, but ES modules imported via require are. Therefore, in this case, Node will let you add properties to the module object and Bun won't. (The behavior differs slightly if you import a module via import. In that case, Bun and Node will treat an ES module as frozen and sealed and a CommonJS module as sealed but not frozen. This detail isn't relevant to this issue, though.)

Ideally, Bun's heuristics should, if the current version decides a module is ambiguous, check for "use strict" at global scope and declare the module to be a CommonJS module if it's found. This is because ES modules are in strict mode by default, so there's no reason to add an explicit "use strict", but "use strict" at global scope is perfectly sensible in a CommonJS module. If we change the heuristic as described in a future version of Bun, it will fix this issue.

It happens also with the latest bun version 1.1.38

Thanks

@jakpop jakpop added bug Something isn't working needs triage labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant