Reputation: 1095
I'm working on a project that I have to give to some guys.
The project is in typescript and so they have to run the command tsc
to compile.
The problem is when I run this command after doing npm install typescript
it seem that the command doesn't exist but if I install with the -g option then it works.
But I really would like the possibility to the futur owner of the project to just have to run npm install without installing dependencies on his computer.
But is it even possible ?
btw I'm on ubuntu 20
Thanks !
Upvotes: 4
Views: 6962
Reputation: 179
If you have your dependencies installed via a package.json
and you have yarn
installed you can run yarn tsc
Upvotes: 0
Reputation: 2816
They can run it from the node_modules folder too.
./node_modules/typescript/bin/tsc
Or if you don't like that you could use npx
which runs binaries from local node_modules
folder.
npx tsc
Upvotes: 2
Reputation: 1075567
npm install typescript
installs it locally to the project. I would go further and add --save-dev
so it only gets listed under devDependencies
, not dependencies
.
You can still run TypeScript in that situation. Your best bet is to add entries to the "scripts"
key in package.json
, like this:
{
"name": "blah",
"version": "1.0.0",
"description": "...",
"scripts": {
"build": "tsc command arguments go here"
},
"keywords": [],
"author": "...",
"license": "...",
"devDependencies": {
"typescript": "^4.5.5"
}
}
Then you run that command via:
npm run build
Node.js will find tsc
in node_modules
and run it.
Upvotes: 5