Reproduction link or steps
REPL
What is expected?
No error happens
What is actually happening?
The following error happens:
Error: Build failed with 1 error:
[PARSE_ERROR] Error: Cannot assign to 'arguments' in strict mode
╭─[ index.cjs:5:1 ]
│
5 │ arguments = 1
│ ────┬────
│ ╰──────
───╯
System Info
Any additional comments?
This code is valid in non-strict mode (sloppy mode). While ESM is always in strict mode, CJS is not. So this should not cause an error.
The fix is to use the correct ModuleKind when parsing:
- For
ModuleDefFormat::CJS || Cts || CjsPackageJson, use ModuleKind::Script
- For
ModuleDefFormat::EsmMjs || EsmMts || EsmPackageJson, use ModuleKind::Module
- For
ModuleDefFormat::Unknown, use ModuleKind::Unambiguous
It was tried in #7003, but is blocked by oxc-project/oxc#15541