What's wrong with my typescript compiler? `tsc --version` returns nothing

吃可爱长大的小学妹 提交于 2020-01-02 02:35:07

问题


In Linux Mint, I've installed node and used it to install typescript. With a working typescript installation, tsc --version should return the version number. In my case, nothing is returned at all.

When I run which tsc the result is /usr/local/bin/tsc.

When I run cat /usr/local/bin/tsc the result is:

#!/usr/bin/env node
require('../lib/tsc.js')

When I run find /usr/local -name 'tsc*' the result is:

/usr/local/bin/tsc
/usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/lib/node_modules/typescript/lib/tsc.js

Does that look correct? If so, then any ideas on what else to look at would be appreciated?

Note I also tried running /usr/local/lib/node_modules/typescript/bin/tsc --version and got the same result ie nothing.


回答1:


In my case on Ubuntu 16.04 the problem was because of I performed sudo apt-get install node-typescript, which delivered me broken tsc. After removing it via apt-get remove and then installing as recommended with npm install -g typescript, it worked fine.

Maybe this will help someone.




回答2:


I discovered that running node --version returns nothing (but shouldn't) however nodejs --version works (the result being v0.10.25). Reinstalling node didn't fix this. I don't know why this would be the case, as I think I followed the recommended installation procedure.

However, editing file /usr/local/bin/tsc and changing the line:

#!/usr/bin/env node

to

#!/usr/bin/env nodejs

seemed to work. Now tsc --version returns message TS6029: Version 1.6.2 and I'm getting .js files generated when I run make.




回答3:


I was getting the following error in Ubuntu 16.04.6 :

  internal/modules/cjs/loader.js:638
   throw err;
   ^

Error: Cannot find module 'typescript/tsc.js'
   at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
   at Function.Module._load (internal/modules/cjs/loader.js:562:25)
   at Module.require (internal/modules/cjs/loader.js:690:17)
   at require (internal/modules/cjs/helpers.js:25:18)
   at Object.<anonymous> (/usr/bin/tsc:2:1)
   at Module._compile (internal/modules/cjs/loader.js:776:30)
   at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
   at Module.load (internal/modules/cjs/loader.js:653:32)
   at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
   at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Running : npm install -g typescript didn't resolved the issue. So, I had to install the latest version of node i.e nvm install <nvm version>

Then with npm install , it fixed the issue.



来源:https://stackoverflow.com/questions/32835203/whats-wrong-with-my-typescript-compiler-tsc-version-returns-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!