我正在尝试使用 Angular 来开发 google 扩展,但发现如果不生成
我就无法引用chrome
对象
ERROR in E:/ChromeExtensions/.../node_modules/chrome-promise/chrome-promise.d.ts (2160,66): Cannot find namespace 'chrome'.
或
ERROR in E:/ChromeExtensions/.../src/app/chrome-tabs.servi ce.ts (14,7): Cannot find name 'chrome'.
我已经添加了 chrome 类型 npm install --save @types/chrome
但它给我的只是类型,但它没有解决构建错误。
如果这很重要:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.4.9
node: 6.11.4
os: win32 x64
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.9
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4
Visual Studio Code 1.17.2
有什么建议吗?
最佳答案
基于 How to use chrome-app.d.ts type in angular-cli 1.0.1 app?
- 我添加了
@types/chrome
到 package.json - 我添加了
/// <reference types="chrome"/>
到我的 ts 文件的顶部
关于javascript - 找不到命名空间/名称 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47075437/