3

Seems like I'm having a problem with whats supposed to be very simple, I want to have typescript as a devDependency in my project and not global.

Ive installed it using npm i --save-dev typescript, but i cannot seem to be able to run tsc command to produce my javascript files.

My tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "atom": {
    "rewriteTsconfig": false
  }
}

I've tried following this question but couldn't find any solution there..

I understand simply running tsc in my terminal cannot possibly work as it is not installed globally and is not a known command, but what IS the way?

Any help would be highly appreciated, thanks in advance!

2
  • The npm run tsc approach that is described in one of the answers in your linked question should work. Commented Apr 21, 2017 at 13:20
  • @Matthias247 thanks for the quick reply, unfortunately adding this script does not work Commented Apr 21, 2017 at 13:41

2 Answers 2

3

standalone tsc command is available only for global installation. When you install it as a devDependency you have to use it with npx before the tsc command like so: npx tsc -v

The reason for this can be found here: https://www.typescriptlang.org/fr/download

It is also good to understand difference between npm and npx commands.

Sign up to request clarification or add additional context in comments.

Comments

1

One way to do it is to define a script inside your package.json like so:

"scripts": {
    "start": "./node_modules/typescript/bin/tsc"
}

To run it: npm run start

Because you added typescript to your devDependencies, this should always be available.

2 Comments

Thanks for the quick reply, unfortunately, doing as you suggest does not solve the problem. i even tried running it manually from within the typescript package.. any idea why? npm just throws the most generic error saying exit status 1
Your error is most likely coming from somewhere else and not from running TSC. Can you provide the detailed error output/trace?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.