Commit 674c150
committed
module: throw error for ESM syntax in explicit commonjs entry
When a main entry point contains ESM syntax but is in a package with
"type": "commonjs" in package.json, the module would silently exit
with code 0 without executing or showing any error. This happened
because the CJS loader detected ESM syntax, attempted to defer to
ESM loading, but the async execution never completed before the
process exited.
This change throws ERR_REQUIRE_ESM for main modules with ESM syntax
in explicitly CommonJS-typed packages, providing a clear error message
instead of silent failure.
Fixes: #611041 parent 13073a9 commit 674c150
File tree
4 files changed
+51
-0
lines changed- lib/internal/modules/cjs
- test
- es-module
- fixtures/es-modules/package-type-commonjs-esm-syntax
4 files changed
+51
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1751 | 1751 | | |
1752 | 1752 | | |
1753 | 1753 | | |
| 1754 | + | |
1754 | 1755 | | |
1755 | 1756 | | |
1756 | 1757 | | |
| |||
1777 | 1778 | | |
1778 | 1779 | | |
1779 | 1780 | | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
1780 | 1786 | | |
1781 | 1787 | | |
1782 | 1788 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments