我似乎无法使用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"
]
}
的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"
}
}
答案 0 :(得分:2)
您可能使用“npm install”安装依赖项。这意味着他们不在路径中。这就是为什么直接使用tsc命令不起作用。
当使用“npm run start”时,我怀疑并发使用路径做一些能够使用来自node_modules文件夹的typescript(及其tsc命令)等库。
像“$(npm bin)”这样的东西就像这样使用:
> $(npm bin)/tsc
有关详细信息,请参阅此问题:
本文也可能对您感兴趣: