Cannot find module 'ts-node/register' in global

See original GitHub issue

It work on locally install, but not work on globally install

npm install ts-node -g
npm install typescript -g
package.json
{
  ...
  scripts: {
    ....
    "test": "mocha --require ts-node/register test/*.ts
  }
}

when run npm run test, it throwing:

   Error: Cannot find module 'ts-node/register'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)                                                  
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)                                                             
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at requires.forEach.mod (/home/s97712/extdata/sqlbind.js/node_modules/mocha/bin/_mocha:511:3)                                
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/s97712/extdata/sqlbind.js/node_modules/mocha/bin/_mocha:510:10)                                 
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)                                                     
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)                                                              
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)                                                           
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
blakeembreycommented, Feb 1, 2019

@lukepighetti Probably an obvious question, but did you do an npm install? That’s a normal node.js error with being unable to resolve the module from your working directory. E.g., if you do ls node_modules/ts-node/register do you see an index.js file?

0reactions
ColonniGiovannicommented, Nov 3, 2022

I also have this error, and I have the dependencies installed both globally and locally, but I still get this:

env TS_NODE_COMPILER_OPTIONS='{"module": "commonjs" }' mocha --require /node_modules/ts-node/register 'tests/**/*.ts'


✖ ERROR: Error: Cannot find module '/node_modules/ts-node/register'
Require stack:

After this I notice the path in the --require flag and I modify it as: env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha --require ./node_modules/ts-node/register 'test/**/*.ts'"

With the ./node_modules/.. I manage to solve it! I hope that it can help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'ts-node/register'
This solution doesn't need you to install ts-node globally. And it works cross platform and for everyone. Share.
Read more >
Cannot find module 'ts-node/register' in VS Code Debug
I have install ts-node globally instead of making package dependency. I tried to link local package to the global one and that was...
Read more >
Cannot find module 'ts-node/register' Error in TypeScript
To solve the error "Cannot find module 'ts-node/register'", install ts-node and typescript as development dependencies by running npm install --save-dev ...
Read more >
ts-node
This error is thrown by node when a module is require() d, but node believes it should execute as native ESM. This can...
Read more >
ts-node Run Configuration error
Error: Cannot find module 'ts-node/register' ... fine if I run it from iTerm with the globally installed ts-node but not within IntelliJ.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found