question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error TS2304: Cannot find name 'Promise'

See original GitHub issue

Hi. I would like to build a golang+angular2 web stack skeleton. In this way I’ve cloned this repo to use as angular2 skel. but it seems not to be working . I simply did the following.

#git clone  https://github.com/angular/quickstart  my-proj
#cd my-proj/
 #npm install
 #npm start

And we got this error. How can I fix it ?

[root@grafanalab01 my-proj]# npm start

> angular2-quickstart@1.0.0 start /root/my-proj
> tsc && concurrently "tsc -w" "lite-server"

node_modules/angular2/platform/browser.d.ts(77,90): 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'.
node_modules/angular2/src/core/application_ref.d.ts(83,60): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(83,146): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(96,51): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(96,147): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(133,90): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(171,81): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(14,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(24,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(25,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,103): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,135): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/compiler.d.ts(12,50): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/compiler.d.ts(16,41): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(108,136): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(156,150): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(197,128): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(203,127): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(204,141): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(205,119): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/render/api.d.ts(13,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(14,84): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(99,41): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(100,22): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(101,25): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(71,59): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/mock/mock_application_ref.d.ts(12,80): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/platform/browser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/platform/dom/dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/testing/matchers.d.ts(4,37): error TS2503: Cannot find namespace 'jasmine'.
node_modules/angular2/src/testing/test_component_builder.d.ts(118,43): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(35,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(50,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(89,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(94,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(94,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(46,62): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(47,42): error TS2304: Cannot find name 'Iterator'.
node_modules/rxjs/Observable.d.ts(103,74): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(103,84): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(143,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(158,65): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(201,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(206,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(206,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/ForkJoinObservable.d.ts(6,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/ForkJoinObservable.d.ts(7,58): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/FromObservable.d.ts(7,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/FromObservable.d.ts(7,51): error TS2304: Cannot find name 'Iterator'.
node_modules/rxjs/observable/PromiseObservable.d.ts(9,31): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/PromiseObservable.d.ts(10,26): error TS2304: Cannot find name 'Promise'.
app/app.component.spec.ts(26,18): error TS2339: Property 'toEqual' does not exist on type 'NgMatchers'.
app/app.component.spec.ts(36,67): error TS2339: Property 'toBe' does not exist on type 'NgMatchers'.
app/app.component.spec.ts(46,30): error TS2339: Property 'toMatch' does not exist on type 'NgMatchers'.

npm ERR! Linux 2.6.32-573.8.1.el6.x86_64
npm ERR! argv "/usr/local/bin/node" "/root/.npm-global/bin/npm" "start"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! angular2-quickstart@1.0.0 start: `tsc && concurrently "tsc -w" "lite-server" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular2-quickstart@1.0.0 start script 'tsc && concurrently "tsc -w" "lite-server" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc && concurrently "tsc -w" "lite-server"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2-quickstart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/my-proj/npm-debug.log

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:49 (6 by maintainers)

github_iconTop GitHub Comments

60reactions
bedrincommented, Aug 15, 2016

Another way to fix it is to change target to es6 in your tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    }
}
40reactions
layton-glympsecommented, Oct 22, 2016

Don’t change your target to ES6!!

@bedrin I don’t mean this to be condescending or rude, but do you understand what changing your target to ES6 means? Am I the only person who thinks that is a bad solution? Having a target of ES6 means that the Typescript compiler is going to compile your Typescript code not to ECMAScript 5, but ECMAScript 6. ES6 is quite far from being fully supported. See the Kangax ES6 compatibility tables if you are uncertain of this. If your project is going live on the internet, and it likely is, you probably want users with the non-latest browsers (IE11, 10, 9, many phone browsers) to still be able to use your product. Safari doesn’t even support a single part of the fat arrow function syntax, for instance.

Why does it fix the error, then? The reason setting your target to ES6 works is because ES6 natively supports promises.

For anyone else who is coming here and thinks that targeting ES6 is a mistake here’s the deal:

As of the time of this writing we should be using Typescript 2.0+. There’s really no good reason not to with angular in final release status. The NG2 quickstart now provides TS2.0+ as a default starter version in their package.json, and the Typescript team is focused on it

There are a few typings definitions needed for Angular. The new recommendation according to TS is to use NPM to manage your Typings, and we can finally ditch this huge confusing headache that was Typings definitions/config files. Angular 2 uses core-js, so we need to use:

npm install --save-dev @types/core-js

Many of your other cannot find name [some-symbol] errors will/should now be solved by simply installing your typings via NPM to your package.json. I don’t even have a typings.config file anymore.

Sounds too good to be true, doesn’t it? Well it’s not. It’s the future, and we’re already in it. Sweet.

Read more here on the TS 2.0 way to consume typings.

P.S. I do still think that finding typings definitions is the biggest pain, since there is usually no good correlation between a “missing name” and what typings definition actually provides support for that, but that’s a different (and very frustrating) topic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS2304: Cannot find name 'Promise' - node.js
You just need to change your target to es6 inside your tsconfig.json to resolve this issue. { "version":"2.13.0", "compilerOptions": ...
Read more >
typescript compilation errors "Cannot find name 'Promise'"
ts(139,29): error TS2304: Cannot find name 'Map'. i fix by removing in Map<string, string> | in setEnvironment(env: Map<string, string> | {[name ...
Read more >
TS2304 -- Cannot find name 'Promise' - Visual Studio Feedback
I am trying to use a Promise in my Node.js Console App. I get a TS2304 error: Build:Cannot find name 'Promise'. I cannot...
Read more >
Typescript Can t find names - Error cannot find name
d.ts(1,10): Error TS2304: Cannot find name 'Promise'. node_modules/angular2/src/core/facade/promise.d.
Read more >
Cannot find name 'require' Error in TypeScript
To solve the Cannot find name require error, install the `node` types by running `npm i -D @types/node`. If the error is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found