最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Missing TypeScript type definitions for the @Angular packages in Angular 2 - Stack Overflow

programmeradmin0浏览0评论

Now that I have updated my application to Angular2 v2.0.0-rc.1, I am once again seeing TypeScript pile error/warning messages when my application is being bundled in webpack. The messages e up for any of the @angular packages I reference from my TypeScript source files, such as these:

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/mon'.

ERROR in ./src/app/app.ts
(4,30): error TS2307: Cannot find module '@angular/http'.

With the earlier beta versions of Angular2, I got around similar message problems with classes like Promise and Map by including something like this at the top of my app.ts file.

///<reference path="node_modules/angular2/typings/browser.d.ts"/>

Is there a d.ts file for the @angular Angular2 packages that I can refer to to fix the problem? So far it doesn't seem like the typings system has anything available:

MFO-Mac:angular2-oauth2 mfo$ typings search '@angular'
No results found for search

Right now I have my TypeScript tsconfig.json file configured to target ES6. But if I change it to target ES5 instead, I don't get these @angular errors, but I instead get errors for mon ES6 classes like Promise, Set, and Map. Here's my file configured for ES6:

{
  "version": "1.6.2",
  "pilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "monjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_ponents",
    "bootstrap"
  ],
  "files": [],
  "definitions": [
  ]
}

I suspect that there are files in node_modules/@angular that I could list in the definitions section of the tsconfig.json file, but I don't currently know enough about how TypeScript typedef files work.

If there is another way to get around this problem, I'd certainly be open to that as well.

Now that I have updated my application to Angular2 v2.0.0-rc.1, I am once again seeing TypeScript pile error/warning messages when my application is being bundled in webpack. The messages e up for any of the @angular packages I reference from my TypeScript source files, such as these:

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/mon'.

ERROR in ./src/app/app.ts
(4,30): error TS2307: Cannot find module '@angular/http'.

With the earlier beta versions of Angular2, I got around similar message problems with classes like Promise and Map by including something like this at the top of my app.ts file.

///<reference path="node_modules/angular2/typings/browser.d.ts"/>

Is there a d.ts file for the @angular Angular2 packages that I can refer to to fix the problem? So far it doesn't seem like the typings system has anything available:

MFO-Mac:angular2-oauth2 mfo$ typings search '@angular'
No results found for search

Right now I have my TypeScript tsconfig.json file configured to target ES6. But if I change it to target ES5 instead, I don't get these @angular errors, but I instead get errors for mon ES6 classes like Promise, Set, and Map. Here's my file configured for ES6:

{
  "version": "1.6.2",
  "pilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "monjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_ponents",
    "bootstrap"
  ],
  "files": [],
  "definitions": [
  ]
}

I suspect that there are files in node_modules/@angular that I could list in the definitions section of the tsconfig.json file, but I don't currently know enough about how TypeScript typedef files work.

If there is another way to get around this problem, I'd certainly be open to that as well.

Share Improve this question asked May 5, 2016 at 20:09 Michael OrylMichael Oryl 21.7k15 gold badges81 silver badges118 bronze badges 1
  • my answer to a similar issue may help you: stackoverflow./a/36948893/3532945 – brando Commented May 6, 2016 at 2:39
Add a ment  | 

1 Answer 1

Reset to default 5

It seems that the TypeScript piler is smart enough to suss out the files definition files itself if you tell it that you are using Node/NPM style modules.

By adding "moduleResolution": "node", to my tsconfig.json file, the problem messages disappeared and the application continued to work as expected.

Here's my new file (the new addition is the 4th line):

{
  "version": "1.6.2",
  "pilerOptions": {
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "monjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_ponents",
    "bootstrap"
  ],
  "files": [],
  "definitions": []
}
发布评论

评论列表(0)

  1. 暂无评论