3

I can't seem to compile my Typescript using the npm run ts" command. What i find a little weird is that i can run the npm start and that way it compiles and runs fine.

The log is below:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'run', 'tsc' ]
2 info using npm@2.11.3
3 info using node@v0.12.7
4 verbose run-script [ 'pretsc', 'tsc', 'posttsc' ]
5 info pretsc MyProject@1.0.0
6 info tsc MyProject@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info MyProject@1.0.0 Failed to exec tsc script
9 verbose stack Error: MyProject@1.0.0 tsc: `tsc`
9 verbose stack Exit status 2
9 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
9 verbose stack     at EventEmitter.emit (events.js:110:17)
9 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack     at ChildProcess.emit (events.js:110:17)
9 verbose stack     at maybeClose (child_process.js:1015:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
10 verbose pkgid MyProject@1.0.0
11 verbose cwd /Users/kasperlaursen/adnexio.frontend
12 error Darwin 15.3.0
13 error argv "node" "/usr/local/bin/npm" "run" "tsc"
14 error node v0.12.7
15 error npm  v2.11.3
16 error code ELIFECYCLE
17 error MyProject@1.0.0 tsc: `tsc`
17 error Exit status 2
18 error Failed at the MyProject@1.0.0 tsc script 'tsc'.
18 error This is most likely a problem with the MyProject package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     tsc
18 error You can get their info via:
18 error     npm owner ls MyProject
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "./bin"
  },
  "exclude": [
    "node_modules"
  ]
}

PACKAGE.JSON:

{
  "name": "MyProject",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.3",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.11"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^2.0.1",
    "typescript": "^1.7.5"
  }
}
Hendy Irawan
  • 20,498
  • 11
  • 103
  • 114
Habber
  • 97
  • 2
  • 9

1 Answers1

3

You probably install your dependencies using the "npm install". This means that they aren't in the path. That's why using the tsc command directly doesn't work.

When using "npm run start", I suspect concurrent to do something with the path to able to use libraires like typescript (and its tsc command) from the node_modules folder.

Something like "$(npm bin)" does when used like that:

> $(npm bin)/tsc

See this question for more details:

This article could also interest you:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • This seems do to the job even tho i get the error: `node_modules/angular2/src/facade/promise.d.ts(1,10): error TS2661: Cannot re-export name that is not defined in the module.` – Habber Mar 02 '16 at 09:22