Search code examples
typescriptnpmvisual-studio-codenpm-run

Is a different version of tsc used when using npm run?


I have VS Code and a Node.js project using Typescript. In my package.json script block there is an item:

"build-ts": "tsc"

If I run plain tsc on the integrated terminal command line, the compilation is fine. But if I invoke npm run build-ts, it detects syntax errors on one file. The cause of the error seems to be from an older compiler version.

If I run tsc -v on the command line, it shows Version 2.9.2. Does npm run use another version of tsc somewhere?

By the way, is npm run from the package npm-run-script? I ran an npm list and I could not find npm-run-script locally or globally.


Solution

  • The question was solved by comment, yet I'll leave this answer here as a bit more verbose version.

    1. When you execute npm run (or npm run-script), it looks for the executables installed locally first. This allows to use different versions for these executables for every project (for example, if some library is incompatible with new version of tsc). So, if tsc is installed as dependency (or dev dependency), npm run will execute it, not the one installed globally. The same holds with gulp and other CLI tools.

    2. npm run-script is not a package, it's an internal npm command, just like install and others. You can check this with npm help - this command shows the list of all built-in commands at once.