Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 2中@Angular包缺少TypeScript类型定义_Javascript_Angularjs_Typescript_Angular_Webpack - Fatal编程技术网

Javascript Angular 2中@Angular包缺少TypeScript类型定义

Javascript Angular 2中@Angular包缺少TypeScript类型定义,javascript,angularjs,typescript,angular,webpack,Javascript,Angularjs,Typescript,Angular,Webpack,现在我已经更新到Angular2 v2.0.0-rc.1,当我的应用程序被捆绑时,我再次看到TypeScript编译错误/警告消息。我从TypeScript源文件中引用的任何@angular包都会出现这些消息,例如: ERROR in ./src/app/app.ts (1,34): error TS2307: Cannot find module '@angular/core'. ERROR in ./src/app/app.ts (3,76): error TS2307: Cannot f

现在我已经更新到Angular2 v2.0.0-rc.1,当我的应用程序被捆绑时,我再次看到TypeScript编译错误/警告消息。我从TypeScript源文件中引用的任何
@angular
包都会出现这些消息,例如:

ERROR in ./src/app/app.ts
(1,34): error TS2307: Cannot find module '@angular/core'.

ERROR in ./src/app/app.ts
(3,76): error TS2307: Cannot find module '@angular/common'.

ERROR in ./src/app/app.ts
(4,30): error TS2307: Cannot find module '@angular/http'.
对于Angular2的早期beta版,我在
Promise
Map
类中解决了类似的消息问题,在我的
app.ts
文件的顶部包含了类似的内容

///<reference path="node_modules/angular2/typings/browser.d.ts"/>
现在我已经将TypeScript
tsconfig.json
文件配置为以ES6为目标。但是如果我将其改为目标ES5,我不会得到这些
@angular
错误,而是会得到常见ES6类的错误,如
Promise
Set
、和
Map
。以下是我为ES6配置的文件:

{
  "version": "1.6.2",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "bootstrap"
  ],
  "files": [],
  "definitions": [
  ]
}
我怀疑
node_modules/@angular
中有文件可以在
tsconfig.json
文件的
definitions
部分列出,但我目前对TypeScript typedef文件的工作原理知之甚少


如果有其他方法可以解决这个问题,我当然也愿意接受。

如果您告诉TypeScript编译器您使用的是Node/NPM样式的模块,那么它似乎足够聪明,可以自行生成文件定义文件

通过向我的
tsconfig.json
文件添加
“moduleResolution”:“node”
,问题消息消失,应用程序继续按预期工作

这是我的新文件(新添加的是第4行):


我对类似问题的回答可能有助于您:
{
  "version": "1.6.2",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "bootstrap"
  ],
  "files": [],
  "definitions": [
  ]
}
{
  "version": "1.6.2",
  "compilerOptions": {
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "bootstrap"
  ],
  "files": [],
  "definitions": []
}