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
Can't run tests in Typescript #4900
Comments
I can run my tests if I use this flag with node |
I get the similar issue, on my monorepo when test import from another package inside the monorepo |
Node's Please have a closer look on our sample repo mochajs/mocha-examples#47 (comment) and the listed links. Most probably you will find some answers to make TS / ESM run with ts-node. Some comments from my side:
|
The tests in the sample repo doesn't import TS files into the test, which I think is the main issue here. Anyways, using |
Prerequisites
node ../../node_modules/mocha/bin/mocha -r ts-node/register --loader=ts-node/esm
faq
labelnode_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
At first, I was getting this error
Debug Failure. False expression: Non-string value passed to
ts.resolveTypeReferenceDirective, likely by a wrapping package working with an outdated 'resolveTypeReferenceDirectives' signature. This is probably not a problem in TS itself.
Upgraded
ts-node
to latest version and then got this error ``TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts".
Added the
--loader=ts-node/esm
flag and now I'm getting this errorReferenceError: exports is not defined in ES module scope
Played around with
module
andtarget
intsconfig.json
and none has helped. Changingtarget
fromcommonjs
toes2015
gives me error saying that itError: Cannot find module yadayada import from soandso
.I'm out of ideas.
Steps to Reproduce
Expected behavior: Should run tests
Actual behavior: Tests not running due to error mentioned above.
Reproduces how often: 100%
Versions
typescript 4.5.4
ts-node 10.8.2
mocha 10.0.0
Windows 10 64-bit
mocha --version
andnode_modules/.bin/mocha --version
:node --version
:Additional Information
The text was updated successfully, but these errors were encountered: