2016-06-25 29 views
14

Typescriptをインストールして実行したいです(つまり、グローバル依存関係はありません)。Typescriptをnpmにローカルにインストールして実行するには?

{ 
    "name": "foo", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "tsc": "tsc" 
    }, 
    "devDependencies": { 
    "typescript": "^1.8.10" 
    }, 
    "author": "", 
    "license": "ISC" 
} 

が、私はその後、実行します:私は2番目のコマンドを実行したときに

npm install 
npm run tsc 

は、しかし、私はそれがすべてそれを表示することはできませんすっごく多くのエラーを取得

は、ここに私のpackage.jsonファイルです。それのほとんどは、次のようなものです:

NPM-DEBUG.LOGで
../foo/node_modules/typescript/lib/lib.d.ts(5015,5): error TS2300: Duplicate identifier 'webkitTransformOrigin'. 
../foo/node_modules/typescript/lib/lib.d.ts(5016,5): error TS2300: Duplicate identifier 'webkitTransformStyle'. 
../foo/node_modules/typescript/lib/lib.d.ts(5017,5): error TS2300: Duplicate identifier 'webkitTransition'. 
../foo/node_modules/typescript/lib/lib.d.ts(5018,5): error TS2300: Duplicate identifier 'webkitTransitionDelay'. 
../foo/node_modules/typescript/lib/lib.d.ts(5019,5): error TS2300: Duplicate identifier 'webkitTransitionDuration'. 
../foo/node_modules/typescript/lib/lib.d.ts(5020,5): error TS2300: Duplicate identifier 'webkitTransitionProperty'. 

私が取得:パッケージを削除して、グローバルtypescriptですをインストールしても問題が解決することを

0 info it worked if it ends with ok 
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'tsc' ] 
2 info using [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'pretsc', 'tsc', 'posttsc' ] 
5 info lifecycle [email protected]~pretsc: [email protected] 
6 silly lifecycle [email protected]~pretsc: no script for pretsc, continuing 
7 info lifecycle [email protected]~tsc: [email protected] 
8 verbose lifecycle [email protected]~tsc: unsafe-perm in lifecycle true 
9 verbose lifecycle [email protected]~tsc: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/vagrant/foo/node_modules/.bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 
10 verbose lifecycle [email protected]~tsc: CWD: /home/vagrant/foo 
11 silly lifecycle [email protected]~tsc: Args: [ '-c', 'tsc' ] 
12 silly lifecycle [email protected]~tsc: Returned: code: 2 signal: null 
13 info lifecycle [email protected]~tsc: Failed to exec tsc script 
14 verbose stack Error: [email protected] tsc: `tsc` 
14 verbose stack Exit status 2 
14 verbose stack  at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:242:16) 
14 verbose stack  at emitTwo (events.js:100:13) 
14 verbose stack  at EventEmitter.emit (events.js:185:7) 
14 verbose stack  at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14) 
14 verbose stack  at emitTwo (events.js:100:13) 
14 verbose stack  at ChildProcess.emit (events.js:185:7) 
14 verbose stack  at maybeClose (internal/child_process.js:850:16) 
14 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) 
15 verbose pkgid [email protected] 
16 verbose cwd /home/vagrant/foo 
17 error Linux 3.13.0-88-generic 
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "tsc" 
19 error node v5.12.0 
20 error npm v3.10.2 
21 error code ELIFECYCLE 
22 error [email protected] tsc: `tsc` 
22 error Exit status 2 
23 error Failed at the [email protected] tsc script 'tsc'. 
23 error Make sure you have the latest version of node.js and npm installed. 
23 error If you do, this is most likely a problem with the foo package, 
23 error not with npm itself. 
23 error Tell the author that this fails on your system: 
23 error  tsc 
23 error You can get information on how to open an issue for this project with: 
23 error  npm bugs foo 
23 error Or if that isn't available, you can get their info via: 
23 error  npm owner ls foo 
23 error There is likely additional logging output above. 
24 verbose exit [ 1, true ] 

注意を。しかし、npm installを使ってローカルパッケージを再度インストールすると、問題が再現されます。またtsconfig.jsonファイルを持っている必要がありますが、それはまたです--save-devキー

npm install --save-dev typescript 

を使用することができ、開発の依存関係としてプロジェクトに活字体をローカルインストールするには

答えて

10

があなたのpackage.json

にtypescriptですが書き込まれます。例えばTSconfigの詳細については

{ 
    "compilerOptions": { 
    "target": "ES5", 
    "module": "system", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false 
    }, 
    "exclude": [ 
    "node_modules", 
    ".npm" 
    ] 
} 

あなたはここにhttp://www.typescriptlang.org/docs/handbook/tsconfig-json.html

+0

私は 'package.json'でどうやっていたのでしょうか?それはインストールタイプのスクリプトであり、それを私の依存関係に保存するだけです。これはdev依存(通常の依存関係ではない)なので、 'npm install --dev-save'にする必要があります。 –

+0

@YahyaUddinあなたは' tsconfig.json'を持っていますか? – Mikhail

+0

番号。今すぐ追加する –

2

tscをコンパイルする設定ファイルまたは.TS(x)のファイルを必要と見ることができます。ファイルを作成し、あなたの問題の両方を解決するために

以下の内容でtsconfig.jsonと呼ば:

{ 
    "compilerOptions": { 
     "outFile": "../../built/local/tsc.js" 
    }, 
    "exclude": [ 
     "node_modules" 
    ] 
} 

また、あなたがtypingsを使用している場合は、この

tsc --config /path/to/a/tsconfig.json 
+0

私はそれが機能するために除外部分だけが必要でした。また、 ' - config'パラメータを使用する必要はありません。これは、typescriptがプロジェクトのルートに自動的に提供されるように見えるためです。 –

+0

ありがとうございます。私はそのことを知らなかった – Bikas

0

注意して、あなたのNPMの実行を変更します次のようになります。

rm -r typings 
typings install 

電子角度2チュートリアルでは、これを使用する:postinstallコマンドdosen't作業は、それほどのようなグローバルなタイピングをインストールしようとした場合

rm -r typings 
npm run postinstall 
npm start 

npm install -g typings 

ポストインストールとは逆にあなたはまた、次のことを試すことができます。

typings install 

この問題は解決する必要があります。

12

この問題の解決方法を理解するまでにはしばらく時間がかかりました。これは元の質問です。あなたが実行できるように、あなたのpackage.jsonファイルにtscを呼び出すscriptを持っている必要があります:あなたが(スクリプトに含めるだけか)オプションに渡す前に

npm run tsc 

--を含める:

npm run tsc -- -v 

ここでは例package.jsonです:

{ 
    "name": "foo", 
    "scripts": { 
    "tsc": "tsc" 
    }, 
    "dependencies": { 
    "typescript": "^1.8.10" 
    } 
} 
+1

Googleに難しい問題!あなたがそれをグローバルにインストールすることを提案するcliパッケージのためには動作しますが、ローカルにしか望みません! – Cammy

2

あなたは「TSCは、」ローカルプロジェクトパックとして存在することをNPMに伝える必要があります(package.json内の "scripts"プロパティを介して)年齢を指定してから、npm run tscで実行します。 (少なくとも、Macの場合)私はあなたがnpm run tsc -- --initのような任意の活字体のコマンドを実行することができ、その後、この

{ 
    "name": "foo" 
    "scripts": { 
    "tsc": "./node_modules/typescript/bin/tsc" 
    }, 
    "dependencies": { 
    "typescript": "^2.3.3", 
    "typings": "^2.1.1" 
    } 
} 

のように、パッケージ内の実際のコンパイラのパスを追加しなければならなかったことを行うには(引数が最初--後に来ます)。

関連する問題