Reputation: 151
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
Upvotes: 15
Views: 23595
Reputation: 6553
My issue was that my NODE_ENV
environment variable was set to production
.
What this does is it makes npm install
ignore all your devDependencies
so even if you have tsconfig-paths
in your dev dependencies it wont be installed unless you change your environment back.
$ export NODE_ENV=staging
$ npm install
$ export NODE_ENV=production
Upvotes: 0
Reputation: 1
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
.
Upvotes: -2
Reputation: 6999
I ran npm install --save-dev tsconfig-paths
and that error went away.
Upvotes: 19