I want to use mocha to test my TypeScript/Angular2 project. I tried to use ts-node as described here:
npm install -g ts-node
but when running
mocha --require ts-node/register -t 10000 ./**/*.unit.ts
I get an error
Cannot find module 'ts-node/register'
What am I missing here?
To solve the error "Cannot find module 'ts-node/register'", install ts-node and typescript as development dependencies by running npm install --save-dev ts-node typescript . Copied! This will add the ts-node package to the development dependencies of your project.
ts-node is a TypeScript execution engine and REPL for Node. js. It JIT transforms TypeScript into JavaScript, enabling you to directly execute TypeScript on Node. js without precompiling. This is accomplished by hooking node's module loading APIs, enabling it to be used seamlessly alongside other Node.
No you shouldn't use it in production, even though it will cache the compiled files it'll be slower to start and consume more memory because it keeps around an instance of the compiler and files in memory.
Since the answer that works for a lot of people appears to be hidden in the comments, I'll post it as an actual answer to the question, now that it appears the question has been reopened.
I had this problem as well. Not sure why this Q has been closed. but installing ts-node locally fixes this.
npm install ts-node --save-dev
Thanks @Anita, as this was the answer that worked for me too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With