10

I'm trying to run a typescript script with ts-node in CLI, which means I don't have a package.json.

Here's the command I'm trying to run:

npx -p typescript@latest -p ts-node@latest -p @types/node@latest ts-node -T --project scripts/tsconfig.script.json scripts/my-script.ts

It works perfectly fine when I use relative paths inside the script.

Then I'm trying to enhance it by enabling paths from tsconfig.script.json in order to be able to import from them.

I want to use tsconfig-paths for it. Here're the command I'm trying to run:

npx -p typescript@latest -p ts-node@latest -p @types/node@latest -p tsconfig-paths@latest ts-node -T -r tsconfig-paths/register --project scripts/tsconfig.script.json scripts/my-script.ts

However, I'm getting the following error:

Error: Cannot find module 'tsconfig-paths/register'

I've tried to play around with order of arguments of ts-node as well as adding/removing options, however, I still cannot make it work and see the tsconfig-paths package.

Am I missing smth?

Thanks in advance

Michael Khaliavski
  • 101
  • 1
  • 1
  • 5

2 Answers2

15

I ran npm install --save-dev tsconfig-paths and that error went away.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
0

Depending on your node version, you can add the following key to your package.json:

"engines": {
  "^16.15.0"
}

This should fix the issue without requiring to install tsconfig-paths.

Frag
  • 1