From 46e6e12b0d415799c6bd5325cd41847215c25563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kiss?= Date: Wed, 9 Aug 2023 17:29:11 +0200 Subject: [PATCH] fix: es6 module import (#3858) --- test/src/utils/__data__/meaning-of-life.js | 1 + test/src/utils/__data__/meaning-of-life.mjs | 1 + test/src/utils/testRequireModule.js | 21 +++++++++++++++++++++ tsconfig.json | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/src/utils/__data__/meaning-of-life.js create mode 100644 test/src/utils/__data__/meaning-of-life.mjs create mode 100644 test/src/utils/testRequireModule.js diff --git a/test/src/utils/__data__/meaning-of-life.js b/test/src/utils/__data__/meaning-of-life.js new file mode 100644 index 0000000000..888cae37af --- /dev/null +++ b/test/src/utils/__data__/meaning-of-life.js @@ -0,0 +1 @@ +module.exports = 42; diff --git a/test/src/utils/__data__/meaning-of-life.mjs b/test/src/utils/__data__/meaning-of-life.mjs new file mode 100644 index 0000000000..7a4e8a723a --- /dev/null +++ b/test/src/utils/__data__/meaning-of-life.mjs @@ -0,0 +1 @@ +export default 42; diff --git a/test/src/utils/testRequireModule.js b/test/src/utils/testRequireModule.js new file mode 100644 index 0000000000..12b800cbfd --- /dev/null +++ b/test/src/utils/testRequireModule.js @@ -0,0 +1,21 @@ +const {strict: assert} = require('node:assert'); +const path = require('node:path'); + +const common = require('../../common.js'); +const requireModule = common.require('utils/requireModule.js'); + +describe('test requireModule', function () { + it('should load commonjs file', function () { + const modulePath = path.join(__dirname, './__data__/meaning-of-life.js'); + const meaningOfLife = requireModule(modulePath); + + assert.equal(meaningOfLife, 42); + }); + + it('should load es6 module', async function () { + const modulePath = path.join(__dirname, './__data__/meaning-of-life.mjs'); + const meaningOfLife = await requireModule(modulePath); + + assert.equal(meaningOfLife, 42); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 8a90298884..78c3204d8c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "node16", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */