Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'ts-node/register'

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?

like image 950
lenny Avatar asked Dec 01 '16 12:12

lenny


People also ask

Can not find module ts-node?

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.

What is ts-node register?

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.

Can I use ts-node in production?

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.


1 Answers

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.

like image 168
Louie Bertoncin Avatar answered Sep 24 '22 17:09

Louie Bertoncin