How to Run TypeScript file directly on Sublime text (node installed by NVM)
Step-1: install depencies : must have node installed already
$ npm install -g typescript : convert *.ts => *.js $ npm install -g ts-node : can run .ts file directly no need compile to .js file first
Step-2: create build-file and add bello code:
- Sublime Text: Tools > built System > New Built >
- $ which node : replace command with your node-location
{
"cmd": ["/usr/bin/node", "$file"],
"selector" : "source.ts"
}
Step-3: Testing
` *.ts file
const name = ‘user-name’
console.log({ name })
`
- Ctrl + B => which you give when building New-Built
How to Run TypeScript file directly on Sublime text (node installed by NVM)
We can install node in 2 ways:
- install from node package or PPA or compile from binary file
- install via NVM (Node Package Manager)
For Method-1: installed node directly
Step-1: install depencies : must have node installed already
$ npm install -g typescript : convert *.ts => *.js $ npm install -g ts-node : can run .ts file directly no need compile to .js file first
Step-2: create build-file and add bello code:
- Sublime Text: Tools > built System > New Built >
- $ which node : replace command with your node-location
{
"cmd": ["/usr/bin/node", "$file"],
"selector" : "source.ts"
}
Step-3: Testing
` *.ts file
const name = ‘user-name’
console.log({ name })
`
- Ctrl + B => which you give when building New-Built
For Method-2: installed node via NVM
- If you follow the above method ‘Method-1’ then it will not work, it will says:
Error: . /usr/bin/env: ‘node’: No such file or directory
because sublime-text did not find your node, even though you put absolute path:
{
"cmd": ["/usr/bin/node", "$file"],
"selector" : "source.ts"
}
to
{
"cmd": ["/home/riajul/.nvm/versions/node/v20.12.2/bin/node", "$file"],
"selector" : "source.ts"
}
We can fix this problem very simple, by adding node into /usr/bin/node with symbolic link
$ ln -s $(which node) /usr/bin/node $ ln -s $(which ts-node) /usr/bin/ts-node
NB:
. Tested on my Linux machine, for window user just replace your path manually