Luk*_*ela 8 javascript google-chrome-extension angular
我正在尝试使用 Angular 来开发 google 扩展,但发现我无法在chrome不生成
E:/ChromeExtensions/.../node_modules/chrome-promise/chrome-promise.d.ts (2160,66) 中的错误:找不到命名空间“chrome”。
或者
E:/ChromeExtensions/.../src/app/chrome-tabs.service.ts (14,7) 中的错误:找不到名称“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
Run Code Online (Sandbox Code Playgroud)
有什么建议?
nag*_*hun 17
基于如何在 angular-cli 1.0.1 应用程序中使用 chrome-app.d.ts 类型?
@types/chrome到 package.json/// <reference types="chrome"/>到我的 ts 文件的顶部jpr*_*dev 12
我也是同样的情况。我正在使用 Angular 创建 Chrome 扩展:
| 包裹 | 版本 |
|---|---|
| @角 | 14.0.4 |
| @类型/铬 | 0.0.193 |
我安装了 Chrome 类型,如文档中所示(https://www.npmjs.com/package/@types/chrome):
npm install --save @types/chrome
Run Code Online (Sandbox Code Playgroud)
我chrome在types文件中添加了tsconfig.app.json:
npm install --save @types/chrome
Run Code Online (Sandbox Code Playgroud)
之后,我的代码编辑器(PHPStorm)chrome在我的代码中考虑了该关键字。
您可以在代码编辑器 ( https://angular.io/guide/file-struct )中为单个项目打开多个工作区,并且可以配置每个工作区所需的类型(在tsconfig.app.json文件中)。在这种情况下,您的代码编辑器将仅考虑相关和配置的工作区的文件中的类型。
这是我测试此配置的项目:https://github.com/jprivet-dev/chrome-extension-angular-starter-kit。
2019 年更新:
没必要再用/// <reference types="chrome"/>了。npm i @types/chrome应该够了。
当您克隆已经@types安装了库的存储库时,有时会发生这种情况。npm i没有完成,但是如果您@types再次安装该库,它应该可以工作。