Skip to content

Commit

Permalink
Update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 26, 2021
1 parent 6953ce5 commit 807e59f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/runtime-integration/expected-cjs-10.txt
Expand Up @@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: function
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
================= require - esm =====================
Error: Unexpected token export
Error: Unexpected identifier
=============== require - corejs ====================
typeof Set: function
arr: 1,2,3
2 changes: 1 addition & 1 deletion test/runtime-integration/expected-cjs-absolute-10.txt
Expand Up @@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: function
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
================= require - esm =====================
Error: Unexpected token export
Error: Unexpected identifier
=============== require - corejs ====================
typeof Set: function
arr: 1,2,3
2 changes: 1 addition & 1 deletion test/runtime-integration/expected-cjs-absolute-13.0.txt
Expand Up @@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: function
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
================= require - esm =====================
Error: Unexpected token 'export'
Error: Cannot use import statement outside a module
=============== require - corejs ====================
typeof Set: function
arr: 1,2,3
6 changes: 5 additions & 1 deletion test/runtime-integration/expected-cjs.txt
Expand Up @@ -3,7 +3,11 @@ typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: function
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
================= require - esm =====================
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/toPrimitive/_index.mjs
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
require() of ES modules is not supported.
require() of <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js from <ROOT>/test/runtime-integration/src/require-esm.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename toPrimitive.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from <ROOT>/packages/babel-runtime/helpers/esm/package.json.

=============== require - corejs ====================
typeof Set: function
arr: 1,2,3
6 changes: 5 additions & 1 deletion test/runtime-integration/expected-esm.txt
Expand Up @@ -12,7 +12,11 @@ typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: function
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
================= require - esm =====================
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/toPrimitive/_index.mjs
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
require() of ES modules is not supported.
require() of <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js from <ROOT>/test/runtime-integration/src/require-esm.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename toPrimitive.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from <ROOT>/packages/babel-runtime/helpers/esm/package.json.

=============== require - corejs ====================
typeof Set: function
arr: 1,2,3
8 changes: 6 additions & 2 deletions test/runtime-integration/node.cjs
Expand Up @@ -4,8 +4,12 @@ const fs = require("fs");

const [major, minor] = process.versions.node.split(".").map(n => +n);

if (major > 12 || (major === 12 && minor >= 17)) {
test("ESM", "--experimental-modules ./src/main-esm.mjs", "expected-esm.txt");
if (
major > 13 ||
(major === 12 && minor >= 17) ||
(major === 13 && minor >= 2)
) {
test("ESM", "./src/main-esm.mjs", "expected-esm.txt");
// TODO: This never worked in any Babel version
// test("ESM - absoluteRuntime", "--esperimental-modules ./src/absolute/main-esm.mjs", "expected-esm-absolute.txt");
}
Expand Down

0 comments on commit 807e59f

Please sign in to comment.