blueprint
blueprint copied to clipboard
DateTime2 components break ts-node execution (testing with mocha)
Environment
- Package version(s): @blueprintjs/datetime2 v0.5.6
- Operating System: Windows 11
- Browser name and version: Google Chrome v105.0.5195.102
Code Sandbox
N/A
Steps to reproduce
- Create a component using one or more of the
@blueprintjs/datetime2package component - Make a simple
.tstest for the component - Set up
ts-nodeandmochato run the tests without the need to compile the.tsfile first - Run the test script. An error should be thrown.
Actual behavior
The following error is thrown before the tests can start running:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".tsx" for path/to/your/file.test.tsx
at new NodeError (node:internal/errors:393:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:80:11)
at defaultGetFormat (node:internal/modules/esm/get_format:122:38)
at defaultLoad (node:internal/modules/esm/load:81:20)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:602:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:458:22)
at new ModuleJob (node:internal/modules/esm/module_job:63:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:477:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:435:34)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:527:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
at async formattedImport (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:7:14)
at async Object.exports.requireOrImport (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:38:28)
at async Object.exports.loadFilesAsync (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:91:20)
at async singleRun (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\cli\run-helpers.js:125:3)
at async Object.exports.handler (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\cli\run.js:370:5)
Expected behavior
Tests should run with no problem with ts-node
Possible solution
Based on the stack trace of the error, it looks like the problem is related to the ES module loader. I couldn't find any different configuration in the @blueprintjs/datetime2 package compared to @blueprintjs/datetime except for one extra dependency in datetime2: "lodash-es": "^4.17.15"
On that same note, if I try to set up mocha to use the experimental ts-node/esm loader I get the following error:
(node:15784) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Repos\orkestra\orkestra-web\node_modules\lodash-es\lodash.js from C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\common\getTimezone.js not supported.
Instead change the require of lodash.js in C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\common\getTimezone.js to a dynamic import() which is available in all CommonJS modules.
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at require.extensions.<computed> [as .js] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\common\getTimezone.js:19:19)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at require.extensions.<computed> [as .js] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\components\date-input2\dateInput2.js:27:21)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at require.extensions.<computed> [as .js] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\components\index.js:19:20)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at require.extensions.<computed> [as .js] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\node_modules\@blueprintjs\datetime2\lib\cjs\index.js:20:22)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at require.extensions.<computed> [as .js] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:851:20)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\src\components\commons\fields\date-field\DateField.component.tsx:5:21)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .tsx] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\src\components\commons\fields\Fields.ts:8:31)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .ts] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\src\components\commons\input-dialog\InputDialog.component.tsx:10:18)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .tsx] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\src\store\main.provider.tsx:10:33)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .tsx] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\src\App.tsx:9:25)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .tsx] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at Object.<anonymous> (C:\Repos\orkestra\orkestra-web\test\integration\App.test.tsx:6:15)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at m._compile (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:857:29)
at require.extensions.<computed> (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at require.extensions.<computed> [as .tsx] (C:\Repos\orkestra\orkestra-web\node_modules\ts-node\dist\index.js:859:16)
at async Promise.all (index 0)
at async formattedImport (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:7:14)
at async exports.requireOrImport (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:38:28)
at async exports.loadFilesAsync (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\nodejs\esm-utils.js:91:20)
at async singleRun (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\cli\run-helpers.js:125:3)
at async exports.handler (C:\Repos\orkestra\orkestra-web\node_modules\mocha\lib\cli\run.js:370:5)