angular: Cannot find name 'Promise'. with beta 7

Hi!

After I have upgraded to angular2 beta 7, I get these errors:

node_modules/angular2/platform/browser.d.ts(77,90): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/common/pipes/async_pipe.d.ts(25,38): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/compiler/xhr.d.ts(6,23): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/compiler/xhr_mock.d.ts(10,23): error TS2304: Cannot find name 'Promise'.
...and more

Here is the full version of it http://pastebin.com/eXDwwmPa

dependencies in my package.json:

  "dependencies": {
    "angular2": "^2.0.0-beta.7",
    "angular2-jwt": "^0.1.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "^5.0.0-beta.2",
    "systemjs": "^0.19.6",
    "zone.js": "^0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "jasmine": "^2.4.1",
    "jasmine-core": "2.4.1",
    "lite-server": "^1.3.1",
    "phantomjs-polyfill": "^0.0.1",
    "typescript": "^1.8.0"
  }

Can you help me with it?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 46 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I did faced the same issue in 2.0.0-rc.1 while trying angular2-quickstart resolved issue by updating tsconfig.json “target”: “es5” to “target”: “es6”

Make sure you have a reference to angular typings in your app’s entry point.

See: https://github.com/ericmdantas/angular2-typescript-todo/blob/master/index.ts#L1

i also found adding the typings file directly to my ‘list of files to compile’ works

    var tsResult = gulp
        .src([
            'node_modules/angular2/typings/browser.d.ts',
            'src/**/*.ts'
        ])
        .pipe(gulpTypescript({
            typescript: typescript,
            module: 'commonjs',
            experimentalDecorators: true,
            emitDecoratorMetadata: true,
            declarationFiles: true,
            target: 'es5',
            noImplicitAny: true
        }));

the problem solve when I put

///<reference path="../node_modules/typescript/lib/lib.es6.d.ts"/> 
import { bootstrap }    from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
bootstrap(AppComponent);

but why i have to put that reference is now is not angular on beta? or how do I can handle in a better way this @ericmdantas Is this a problem only for the ts compiler? thanks

@Cedrigax UPDATE SOLUTION

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "noImplicitAny": false,
    "rootDir": ".",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "moduleResolution": "node"
  },
  "exclude": [
    "typings/main.d.ts",
    "typings/main",
    "node_modules"
  ]
}

with that I don’t have to put that reference I really don’t know how is the correct way to use the tsconfing.json but this works without putting the reference at the main.ts

I hit this issue when moving from 2.0.0-beta.0 -> .7/.8 and now I have following in my app/main.ts

// /// <reference path="../node_modules/angular2/typings/browser.d.ts" />  // no longer contains all of es6 type definitions
/// <reference path="../node_modules/typescript/lib/lib.es6.d.ts" />

The reason I concluded was because in my cordova typescript projects I maintain a single (projectRoot)/tsconfig.json which leads me to have to define an "exclude": [ . . . "node_modules" . . . ] entry to keep it from trying to transpile *.ts files found in npm packages. This i’m assuming has the has unwanted side effect of keeping typescript transpiler from being able to walk my node_modules folder to discover and automatically use *.d.ts typing files found in that path.

In the case of my non-cordova typescript projects, e.g. asp.net (dnx) 5 web app/api, I can use a combination of (projectRoot)/app/tsconfig.json + (projectRoot)/scripts/tsconfig.json, instead of single (projectRoot)/tsconfig.json, which in turn doesn’t require me to maintain an "exclude": [ . . . "node_modules" . . . ] entry in those files since everything in those folders and below them is open game for transpiling. Trouble is i’m not finding that typescript can be told to go up a folder level to their parent folder during its discovery process for *.d.ts typing files and so it still doesn’t lead to it automatically picking up the *.d.ts files in (projectRoot)/node_modules folder tree and so I still have to operate with explicit /// <reference /> entry(ies) in app/main.ts .

I’ve been looking around in https://github.com/Microsoft/TypeScript/wiki/tsconfig.json and http://json.schemastore.org/tsconfig to see if there is a tsconfig.json setting that enables telling typescript where specifically look to automatically discover *.d.ts typing files but found nothing as of yet.

This issue to do with tsconfig.json placement and settings leading to the need in some cases to define an app/main.ts /// <reference /> entry I see as being what @dsebastien called out in the issue #7038 link that was provided above.

Thanks @ericmdantas! It solved my problem.

Using the following also works. Tried with typescript 2.0.3

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "es6"]
  }
}

Yeah, if you’re transpiling to es5, you should also install the typings for es6-shim.

Did you run typings install after cloning?

So not sure how true this will be for everyone but I was running into this exact issue and it had to do with npm not installing all the packages maybe due to server issues. But I just deleted my node_modules folder and did another npm install and I didn’t have to use the reference path.

I am having these errors as well. On initial gulp build everything works fine. If I make a change to one of my .ts files, even if it’s just a whitespace change, my gulp file throws a bunch of errors about "Cannot find name ‘module’'. and “Cannot find name ‘Promise’”. Saving it again several times and it starts building properly again, but I think it’s failing on actually outputting the modified files after that.

I have a stackoverflow question with more details on this.

http://stackoverflow.com/questions/35580944/gulp-typescript-emitting-errors-upon-save-but-is-fine-with-subsequent-saves?noredirect=1#comment58946776_35580944

Ionic2 RC0-1 base app contains a tsconfig.json that isn’t compatible with Ionic…

Which option to use? Compiler does not recognize Promise objects.

For me it’s working just fine, see if you can clone this repo: https://github.com/ericmdantas/angular2-typescript-todo and then run npm i, typings install and tsc. There should be no compile errors.