Ara*_*ash 66 visual-studio-code angular
我的项目是使用[Angular CLI] 1.2.6版生成的.
我可以编译项目,它工作正常,但我总是得到错误的vs代码告诉我找不到模块'@ angular/core'找不到模块'@ angular/router'找不到模块.....
我附上了我的tsconfig.json文件的内容,这对我来说真的很令人沮丧,花了2个小时来弄清楚出了什么问题,我还卸载并重新安装了vs代码它不起作用.
这是我的环境规范:
@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
Run Code Online (Sandbox Code Playgroud)
os:微软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
Run Code Online (Sandbox Code Playgroud)
node_module文件夹
-@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
Run Code Online (Sandbox Code Playgroud)
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"
]
}
}
Run Code Online (Sandbox Code Playgroud)
try*_*arn 92
我只是在导入我自己创建的组件/服务时才遇到这个问题对于像你这样的人,对于那些被接受的解决方案不起作用的人,可以试试这个:
加
"baseUrl": "src"
Run Code Online (Sandbox Code Playgroud)
在你的tsconfig.json
.原因是可视代码IDE无法解析基本URL,因此无法解析导入组件的路径并提供错误/警告.
而角度编译器src
默认采用baseurl,因此可以编译.
注意:
您需要重新启动VS Code IDE才能使此更改生效.
编辑:
正如其中一条评论中所述,在某些情况下,更改工作区版本也可能有效.更多细节在这里:https://github.com/Microsoft/vscode/issues/34681#issuecomment-331306869
小智 47
很可能在angular项目中缺少node_modules包,运行:
npm install
Run Code Online (Sandbox Code Playgroud)
在angular项目文件夹中.
joe*_*oey 12
我的修复就是跑
npm install
Run Code Online (Sandbox Code Playgroud)
然后卸载,然后在visual studio中重新加载项目.
在 VSCode 状态栏中,它必须显示打字稿版本 - 像这样
单击该版本号将向您显示可用的不同版本。
如果您使用的是 VSCode 版本,那么切换到 Workspace 版本可以解决问题(如果是 VScode 问题而不是您的tsconfig.json
问题)(我已经在使用该版本,因此未突出显示)
小智 7
我遇到了同样的问题,这可能有两个原因-
src
基本文件夹可能未声明,要解决此问题,请转到tsconfig.json
并添加baseUrl
“ src
”{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
Run Code Online (Sandbox Code Playgroud)
npm install
我angular 5
今天在我的应用程序中遇到了这个问题。而且对我有帮助的修复很简单。我加入"moduleResolution": "node"
到compilerOptions
了在tsconfig.json
文件中。我完整的tsconfig.json
文件内容如下。
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
在moduleResolution
指定模块的解决策略。此设置的值可以是node
或classic
。您可以在这里阅读更多有关此的内容。
小智 6
我遇到了同样的问题,因为我正在尝试在 VS 代码中处理角度项目。
解决此问题的解决方案是。
2.在终端中运行以下命令
npm 安装
然后运行 npmauditfix
然后运行 npmauditfix --force
现在问题将得到解决。
小智 5
尝试使用:
npm audit fix --force
Run Code Online (Sandbox Code Playgroud)
进而:
npm install --save @ng-bootstrap/ng-bootstrap
Run Code Online (Sandbox Code Playgroud)
而不是@ng-bootstrap/ng-bootstrap
全局保存。
小智 5
我有同样的问题。我通过清除位于“ C:\ Users \ Administrator \ AppData \ Roaming \ npm-cache”的 npm缓存来解决了该问题
或者您可以简单地运行:
npm cache clean --force
Run Code Online (Sandbox Code Playgroud)
然后关闭vscode,然后再次打开您的文件夹。
我遇到了同样的问题,很奇怪,因为项目编译并运行时没有错误。我更新了 npm,然后重新安装了软件包
npm update
npm install
Run Code Online (Sandbox Code Playgroud)
那么 VS Code 别再说了。
我遇到过这个问题并通过以下命令修复了它。
npm cache clean --force
npm i @angular/core -s
Run Code Online (Sandbox Code Playgroud)
然后不要忘记重新启动VS code。它必须被修复。
我卸载了已安装的所有扩展,结果发现来自以下地址的 JavaScript 和 TypeScript IntelliSense 扩展导致了问题。 https://marketplace.visualstudio.com/items?itemName=sourcegraph.javascript-typescript
这里的要点是,当您访问该网站时,您会看到有一个黄色标签,告诉您它处于预览版本中,但是当您在 vs 扩展中浏览时,您看不到该标签。
归档时间: |
|
查看次数: |
116783 次 |
最近记录: |