1

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!

Community
  • 1
  • 1
Kesem David
  • 2,135
  • 3
  • 27
  • 46

2 Answers2

2

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.

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.

Saravana
  • 37,852
  • 18
  • 100
  • 108
Jeff Huijsmans
  • 1,388
  • 1
  • 14
  • 35
  • 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 – Kesem David Apr 21 '17 at 13:43
  • Your error is most likely coming from somewhere else and not from running TSC. Can you provide the detailed error output/trace? – Ugo Apr 29 '17 at 00:55