【发布时间】:2018-02-04 19:25:14
【问题描述】:
我的项目是使用 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
操作系统: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"
]
}
}
【问题讨论】:
-
这是因为您已将 angular core 安装为全局。 Intellisense 在 node_modules 中找不到它。
-
角核心在我的node_module中
-
您在
npm install之前是否在vscode中打开了一个项目?如果yes之后您是否尝试重新启动vscode? -
我已经重启了100次
-
能否尝试使用cli生成一个新项目
npm install,然后看看是否有相同的东西?
标签: angular visual-studio-code