VSCode はモジュール '@angular/core' またはその他のモジュールを見つけることができません 質問する

VSCode はモジュール '@angular/core' またはその他のモジュールを見つけることができません 質問する

私のプロジェクトは、Angular CLI バージョン 1.2.6 で生成されました。

プロジェクトをコンパイルして正常に動作しますが、VSCode で常に次のエラーが表示されます:

cannot  find module '@angular/core'
cannot find module '@angular/router'
cannot find module .....

スクリーンショット スクリーンショット

ファイルの内容を添付しましたがtsconfig.json、これは私にとって非常にイライラする問題で、何が問題なのかを理解するのに 2 時間も費やし、VSCode をアンインストールして再インストールしましたが、機能しません。

私の環境仕様は次のとおりです。

@angular/cli: 1.2.6
node: 6.9.1
os: win32 x64
@angular/animations: 4.3.4
@angular/common: 4.3.4
@angular/compiler: 4.3.4
@angular/core: 4.3.4
@angular/forms: 4.3.4
@angular/http: 4.3.4
@angular/platform-browser: 4.3.4
@angular/platform-browser-dynamic: 4.3.4
@angular/router: 4.3.4
@angular/cli: 1.2.6
@angular/compiler-cli: 4.3.4
@angular/language-service: 4.3.4

OS: Microsoft vs 10 エンタープライズ

プロジェクトルートフォルダ

.angular-cli.json
.editorconfig
.gitignore
.vscode
e2e
karma.conf.js
node_modules
package.json
protractor.conf.js
README.md
src
tsconfig.json
tslint.json

node_modulesフォルダ

-@angular
--animations
--cli
--common
--compiler
--compiler-cli
--core
---@angular
---bundles
---core.d.ts
---core.metadata.json
---package.json
---public_api.d.ts
---README.md
---src
---testing
---testing.d.ts
---testing.metadata.json
--forms
--http
--language-service
--platform-browser
--platform-browser-dynamic
--router
--tsc-wrapped
@ng-bootstrap
@ngtools
-@types
--jasmine
--jasminewd2
--node
--q
--selenium-webdriver

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

ベストアンサー1

私は、独自に作成したコンポーネント/サービスをインポートしているときにのみこの問題に直面していました。私のように、受け入れられた解決策が機能しなかった人は、これを試すことができます。

追加

"baseUrl": "src"

tsconfig.json。その理由は、ビジュアル コード IDE がベース URL を解決できないため、インポートされたコンポーネントへのパスを解決できず、エラー/警告が表示されるためです。

一方、Angular コンパイラはsrcデフォルトで baseurl を取得するため、コンパイルできます。

注記:

この変更を有効にするには、VS Code IDE を再起動する必要があります。

編集:

コメントの 1 つで述べられているように、場合によってはワークスペースのバージョンを変更することでも機能する可能性があります。詳細はこちらをご覧ください。https://github.com/Microsoft/vscode/issues/34681#issuecomment-331306869

おすすめ記事