-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts-node/register
not supported in 9.0.0
#4665
Comments
Will look into it tonight. Hopefully, just |
Oh, wait, I see your fix @swansontec. Looks like it will solve it. Thanks! |
I'm surprised that this issue is arising only two weeks after publishing v9.0.0. Is nobody using typescript with ts-node? |
@swantontec, I tried reproducing it, but it works for me: // x.test.ts
function foo(x: number) {
console.log('hi')
}
foo(4) # .mocharc.yaml
require: ['ts-node/register'] $ npm init -y
$ npm i -D ts-node mocha
$ npx mocha x.test.ts
hi
0 passing (0ms) I tried both for Node.js v15.12.0, and v16.3.0. Mocha was v9.0.1, and ts-node was 10.0.0 and 9.1.1. If you could create a repository that reproduces this (including full instructions to reproduce), that would maybe pinpoint the problem? |
@danielgindi @swansontec are you requiring the |
Mot specifically. Simply |
Aha! This only affects old versions of ts-node. Modern versions, such as the current one, have an However, the latest version of Sucrase (3.19.0) still has the issue. Here is a minimal reproduction script: mkdir mocha-demo; cd mocha-demo
yarn add --dev mocha sucrase
echo "console.log('Hey')" > test.ts
yarn mocha -r sucrase/register test.ts So, this does open up the possibility of patching Sucrase to use |
Wait. What would be the correct wait to register ts-node with mocha? |
It works the same as before - you just add The problem is that However, other packages like sucrase do not provide subpath exports in their |
Got it. But for commonjs, if there's no package.json, the default of course is |
@swansontec got it. I'll try and reproduce it without specifically using |
@swansontec yup. got it. Fixing... |
Hey, @swansontec, I just saw you have a PR for this. After I made mine... 😂 Unfortunately, your PR doesn't include a test. If you'd rather you add a test to your PR, we can use yours. Otherwise, I'll add mine. |
@giltayar We should go ahead and use your PR! I will close mine. |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
mocha configuration contains
require: ['ts-node/register']
, in order to load the TS loader.But since
node_modules/ts-node/register
is a folder, the new ESM loader in mocha fails to load, and throws:Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '...../node_modules/ts-node/register' is not supported resolving ES modules imported from ...../node_modules/mocha/lib/esm-utils.js
Steps to Reproduce
npm i --save-dev ts-node
require: ['ts-node/register']
to the.mocharc.yml
Expected behavior: Should work, and at least automatically resolve some well-known loaders like
ts-node
.Actual behavior: Fails miserably.
Reproduces how often: 100%
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 9.0.0node --version
: v15.12.0The text was updated successfully, but these errors were encountered: