3

我似乎无法使用npm run ts" 命令编译我的 Typescript。我发现有点奇怪的是我可以运行它,npm start并且它编译并运行良好。

日志如下:

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"
  ]
}

包.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"
  }
}
4

1 回答 1

3

您可能使用“npm install”安装您的依赖项。这意味着它们不在路径中。这就是为什么直接使用 tsc 命令不起作用的原因。

使用“npm run start”时,我怀疑并发对能够使用 node_modules 文件夹中的 typescript (及其 tsc 命令)之类的库的路径做一些事情。

像 "$(npm bin)" 这样使用的东西:

> $(npm bin)/tsc

有关更多详细信息,请参阅此问题:

这篇文章也可能让您感兴趣:

于 2016-03-01T15:53:04.203 回答