Programmierer aus Leidenschaft. Ich lege besonders Wert auf Clean Code und liebe es mich durch legacy Code zu wühlen... und den dann zu refaktorieren 😉.
For context: My source is in src/ts including tests under src/ts/test. My compiles produce one js (under src/js-tmp) per source ts (under src/ts). My dists cherry-pick from js-tmp (i.e., exclude tests, ...).
OMG finally. I tried to add chai testing to my first typescript app instead of karma, all examples inevitable ended with 'Cannot use import statement outside a module'. Tried babel and configured all jsons possible with no luck.
This one finally highlighted the critical part I needed, and because the example is simple and concise it wasn't lost - env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }'
Full Stack Developer, mainly working in .NET with web technologies and mobile (Xamarin).
WWDC14 Attendee, when Swift was presented, a bit rusty but can work in Swift too.
If you are on Windows env needs to be replaced with set, at least this is what I've read googling around.
That command is related to ts-node as you can read here
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home//node_modules/ts-node/register not supported resolving ES modules imported from /home/mikkel/src//node_modules/mocha/lib/esm-utils.js
Did you mean to import ts-node/register/index.js?
Is pretty much what I get no matter what tutorial I follow.
Full Stack Developer, mainly working in .NET with web technologies and mobile (Xamarin).
WWDC14 Attendee, when Swift was presented, a bit rusty but can work in Swift too.
Great tutorial, thank you!
I tried for like 3 Hours to test my simple typescript code with karma+jasime (because angular is using it so how hard can it be)...
Looked 2mins on this guide and it works like a charme thank you!
Thanks @matteobruni quite helpful.
I was able to test APIs with minor adjustments.
For context: My source is in
src/tsincluding tests undersrc/ts/test. My compiles produce one js (undersrc/js-tmp) per source ts (undersrc/ts). My dists cherry-pick from js-tmp (i.e., exclude tests, ...).`
OMG finally. I tried to add chai testing to my first typescript app instead of karma, all examples inevitable ended with 'Cannot use import statement outside a module'. Tried babel and configured all jsons possible with no luck.
This one finally highlighted the critical part I needed, and because the example is simple and concise it wasn't lost - env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }'
many thanks
'env' is not recognized as an internal or external command,
If you are on Windows
envneeds to be replaced withset, at least this is what I've read googling around.That command is related to
ts-nodeas you can read hereYes, but i had to add
&&.set TS_NODE_COMPILER_OPTIONS={\"module\": \"commonjs\" } && mocha -r ts-node/register 'tests/**/*.ts'Damn windows, I just wasted the last 24hrs just because of this😩!
Thanks a lot.
I have been using npmjs.com/package/cross-env for cross platform support
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home//node_modules/ts-node/register not supported resolving ES modules imported from /home/mikkel/src//node_modules/mocha/lib/esm-utils.js
Did you mean to import ts-node/register/index.js?
Is pretty much what I get no matter what tutorial I follow.
Is
env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }'equivalent of adding this to your tsconfig.jsonIt depends if you need that in your tsconfig, which was not my case
Thanks, was very helpful on a project of mine.
Very helpful article.