2016-05-03 26 views
1

この問題に関する質問と回答がたくさんあるようですが、Windows/Visual Studioのほとんどの回答がありました。私は、私が作業しているTypeScriptプロジェクトでAngular2にOSXとIntelliJを使用していますが、現在、私がangular2ライブラリからインポートしたときに、 "from"の下に警告/エラー(小さな赤い波打ち線)があります。私が持っているもの:IntelliJ&Angular2/TypeScript - エラーTS2307:モジュール 'angular2/...'を見つけることができません。

/// <reference path="node_modules/angular2/ts/typings/node/node.d.ts"/> 
/// <reference path="node_modules/angular2/typings/browser.d.ts"/> 

import { bootstrap } from "angular2/platform/browser"; 
import { Component } from "angular2/core"; 
import { ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from 'angular2/router'; 

すべての3つのインポートステートメントには、fromの場所(ここでは "angular2/...."があります)に警告があります。私はのIntelliJでtypescriptです-compiler.xmlをeditiingことにより、これを修正しようとした:

<?xml version="1.0" encoding="UTF-8"?> 
<project version="4"> 
    <component name="TypeScriptCompiler"> 
    <option name="isCompilerEnabled" value="true" /> 
    <option name="typeScriptServiceDirectory" value="$USER_HOME$/node_modules/typescript/bin" /> 
    <option name="typeScriptCompilerParams" value="-m amd -t ES5" /> 
    <option name="versionType" value="SERVICE_DIRECTORY" /> 
    </component> 
</project> 

私はインポート他のすべてのモジュールが(私は自分自身を書き部品など)細かいですが、私はAngular2からインポートしたものは警告を持っていますか?問題を取り除くためにしばらく努力してきたので、誰もがこのエラー/問題に遭遇しました。私は現在、バージョン1.7.5のTypeScriptがインストールされています。

dev-dependanciesにはtypings.jsonファイルまたはnpm typingsがインストールされていません。

これは私のtsconfig.jsonファイルです:に応じて(すなわち、それは相対パスを使用して固定した私にとって

{ 
    "rules": { 
    "align": [true, 
     "parameters", 
     "arguments", 
     "statements"], 
    "class-name": true, 
    "comment-format": [true, "check-space"], 
    "curly": true, 
    "eofline": true, 
    "forin": true, 
    "indent": [true, "spaces"], 
    "interface-name": true, 
    "label-position": true, 
    "label-undefined": true, 
    "jsdoc-format": true, 
    "max-line-length": [true, 80], 
    "member-ordering": [true, 
     "public-before-private", 
     "static-before-instance", 
     "variables-before-functions" 
    ], 
    "no-arg": true, 
    "no-bitwise": true, 
    "no-console": [true, 
     "debug", 
     "info", 
     "time", 
     "timeEnd", 
     "trace" 
    ], 
    "no-construct": true, 
    "no-debugger": true, 
    "no-duplicate-key": true, 
    "no-duplicate-variable": true, 
    "no-empty": true, 
    "no-eval": true, 
    "no-require-imports": true, 
    "no-shadowed-variable": true, 
    "no-string-literal": true, 
    "no-switch-case-fall-through": true, 
    "no-trailing-comma": true, 
    "no-trailing-whitespace": true, 
    "no-unused-expression": true, 
    "no-unused-variable": true, 
    "no-unreachable": true, 
    "no-use-before-declare": true, 
    "no-var-keyword": true, 
    "one-line": [true, 
     "check-open-brace", 
     "check-catch", 
     "check-else", 
     "check-whitespace" 
    ], 
    "quotemark": [true, "single"], 
    "radix": true, 
    "semicolon": true, 
    "sort-object-literal-keys": false, 
    "triple-equals": [true, "allow-null-check"], 
    "typedef": [true, 
     "call-signature", 
     "parameter", 
     "property-declaration", 
     "variable-declaration", 
     "member-variable-declaration" 
    ], 
    "typedef-whitespace": [true, { 
     "call-signature": "nospace", 
     "index-signature": "nospace", 
     "parameter": "nospace", 
     "property-declaration": "nospace", 
     "variable-declaration": "nospace" 
    }], 
    "variable-name": [true, 
     "allow-leading-underscore"], 
    "whitespace": [true, 
     "check-branch", 
     "check-decl", 
     "check-operator", 
     "check-separator", 
     "check-type" 
    ] 
    } 
} 
+0

どのバージョンのAngular 2を使用しましたか? – Thomas

+0

「angular2」:「2.0.0-beta.16」 –

+0

beta.17へのアップグレードで違いはありません –

答えて

2

{ 
    "compilerOptions": { 
    "target": "ES5", 
    "module": "system", 
    "moduleResolution": "node", 
    "sourceMap": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false 
    }, 
    "files": [ 
    // there is an array of files here 
    ], 
    "filesGlob": [ 
    "app/**/*.ts" 
    ], 
    "exclude": [ 
    "node_modules" 
    ], 
    "atom": { 
    "rewriteTsconfig": true 
    } 
} 

と、これは私のtslint.jsonファイルでありますあなたの.tsファイルの場所):

///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>

また、 Intellij Settingsで "Use tsconfig.json"を有効にしてください。 私の設定ファイルは、次のようになります。

<?xml version="1.0" encoding="UTF-8"?> 
<project version="4"> 
    <component name="TypeScriptCompiler"> 
    <option name="isCompilerEnabled" value="true" /> 
    <option name="typeScriptCompilerParams" value="--module &quot;amd&quot; --target &quot;ES5&quot; --experimentalDecorators" /> 
    <option name="useConfig" value="true" /> 
    </component> 
</project> 

数時間angular2 rc.1

これは、モジュールをインポートする方法に関するいくつかの重大な変更を導入しhttps://github.com/angular/angular/blob/3229bf16656749427d1def38ced0e1d1d2ae1fa4/CHANGELOG.md

をリリースしましたので、またthateに注意してください(例: "角度/コア"は "@角度/コア"になります)。

rcバージョンを使用している場合は、もう///<reference path=".."/>は必要ありません。 (正しく設定されている場合:https://github.com/angular/quickstart/blob/master/systemjs.config.js)System.jsは自動的にnode_modulesディレクトリに対応するindex.d.tsを見つけ

私もES6にターゲットを変更しなければならなかったそう、私は、例えば、エラーメッセージを得ましたMapまたはPromiseは未定義です。 ES5の目標を維持したい場合は、es6-shim(.jsと.d.ts)を含める必要があります

関連する問題