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

Importing cjs file with "module.exports" export causes fatal error #57295

Open
dsherret opened this issue Mar 3, 2025 · 6 comments · May be fixed by #57366
Open

Importing cjs file with "module.exports" export causes fatal error #57295

dsherret opened this issue Mar 3, 2025 · 6 comments · May be fixed by #57366

Comments

@dsherret
Copy link

dsherret commented Mar 3, 2025

Version

23.9.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

No response

What steps will reproduce the bug?

// a.mjs
import * as test from "./b.cjs";

console.log(test);

// b.cjs
module.exports["module.exports"] = 6;

Then node a.mjs

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

Probably:

> node a.mjs
[Module: null prototype] {
  default: { 'module.exports': 6 },
  'module.exports': { 'module.exports': 6 }
}

What do you see instead?

> node a.mjs


#
# Fatal error in , line 0
# Check failed: IsTheHole(exports->Lookup(name), isolate).
#
#
#
#FailureMessage Object: 00000026F33FE980
----- Native stack trace -----

 1: 00007FF73ED9FB1D node::SetCppgcReference+16781
 2: 00007FF73EC7CA1F node::TriggerNodeReport+74543
 3: 00007FF740005231 V8_Fatal+225
 4: 00007FF73F5C5201 v8::MemorySpan<std::basic_string_view<char,std::char_traits<char> > const >::end+4401
 5: 00007FF73F5D7CCC v8::MemorySpan<std::basic_string_view<char,std::char_traits<char> > const >::end+80892
 6: 00007FF73F607EDE v8::RegExp::GetFlags+166382
 7: 00007FF73F9F8698 v8::Module::InstantiateModule+136
 8: 00007FF73ED52C4C v8::base::CPU::has_bmi2+16684
 9: 00007FF73FA1FD6A v8::PropertyDescriptor::writable+79722
10: 00007FF73FA1DF02 v8::PropertyDescriptor::writable+71938
11: 00007FF73FA5F25B v8::PropertyDescriptor::writable+339035
12: 00007FF73FB41219 v8::PropertyDescriptor::writable+1264665
13: 00007FF73FA4DDD3 v8::PropertyDescriptor::writable+268243
14: 00007FF73FA1B953 v8::PropertyDescriptor::writable+62291
15: 00007FF73F8B955A v8::Isolate::NumberOfHeapSpaces+2634
16: 00007FF73F8B964B v8::Isolate::NumberOfHeapSpaces+2875
17: 00007FF73F8BA384 v8::Isolate::NumberOfHeapSpaces+6260
18: 00007FF73F88E257 v8::base::CPU::has_sse41+1671
19: 00007FF73F88DEC0 v8::base::CPU::has_sse41+752
20: 00007FF73EDE4F32 node::CallbackScope::~CallbackScope+530
21: 00007FF73EDE4DAE node::CallbackScope::~CallbackScope+142
22: 00007FF73ECE2946 v8::base::CPU::has_fpu+49734
23: 00007FF73ECFD045 EVP_MD_meth_get_input_blocksize+58213
24: 00007FF73EE1879A uv_timer_stop+1322
25: 00007FF73EE1493B uv_update_time+475
26: 00007FF73EE144A4 uv_run+884
27: 00007FF73EDE4525 node::SpinEventLoop+405
28: 00007FF73ECAD95A v8_inspector::protocol::Binary::operator=+130346
29: 00007FF73ED4E82C node::Start+4796
30: 00007FF73ED4D597 node::Start+39
31: 00007FF73EABF3ED AES_cbc_encrypt+158237
32: 00007FF740725174 inflateValidate+29428
33: 00007FFFF58EE8D7 BaseThreadInitThunk+23
34: 00007FFFF70FBF2C RtlUserThreadStart+44

Additional information

No response

@dsherret
Copy link
Author

dsherret commented Mar 3, 2025

I think the fix is to add a || exportName === "module.exports" here:

if (!ObjectPrototypeHasOwnProperty(exports, exportName) || exportName === 'default') {

@aduh95
Copy link
Contributor

aduh95 commented Mar 3, 2025

Would you like to send a PR?

@dsherret
Copy link
Author

dsherret commented Mar 4, 2025

I would, but I don't want to go through with setting up my development environment.

@joyeecheung
Copy link
Member

cc @guybedford

@guybedford
Copy link
Contributor

I'd be happy to post up a PR on Friday, unless someone else wants to get to it first.

@guybedford guybedford linked a pull request Mar 7, 2025 that will close this issue
@guybedford
Copy link
Contributor

Fix available at #57366.

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.

4 participants