Commit 6ed6c3f
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 a SyntaxError for main modules with ESM syntax
in explicitly CommonJS-typed packages, matching the error Node.js
throws when import syntax appears in other CommonJS contexts.
Fixes: #611041 parent 13073a9 commit 6ed6c3f
File tree
4 files changed
+43
-0
lines changed- lib/internal/modules/cjs
- test
- es-module
- fixtures/es-modules/package-type-commonjs-esm-syntax
4 files changed
+43
-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 | + | |
1780 | 1785 | | |
1781 | 1786 | | |
1782 | 1787 | | |
| |||
| 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 | + | |
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