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
I ran npm install --save-dev tsconfig-paths
and that error went away.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.