Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node projects with --lib es6: cannot find name 'console' #9545

Closed
yortus opened this issue Jul 7, 2016 · 10 comments
Closed

Node projects with --lib es6: cannot find name 'console' #9545

yortus opened this issue Jul 7, 2016 · 10 comments
Assignees
Labels
@types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped

Comments

@yortus
Copy link
Contributor

yortus commented Jul 7, 2016

TypeScript Version: nightly (2.0.0-dev.20160706)

Code

// Before compiling: npm install @types/node
// Compile options: { "lib": ["es6"], "types": ["node"] }
process.cwd();          // OK
console.log('testing'); // ERROR: Cannot find name 'console'

Expected behavior:

Compiles without errors

Actual behavior:

console is not defined

More Info:

node.d.ts does not contain a definition for the global console instance or for the Console class. References to console are resolved against the definitions from lib.dom.d.ts. But now with the --lib option, Node projects can opt out of the ambient DOM typings. That brings up the problem that console is not defined.

It's not as simple as just copying the ambient console and Console definitions from lib.dom.d.ts into node.d.ts, because in browsers the Console constructor is globally available but in Node it is not. 'Hiding' Console under the NodeJS namepace in node.d.ts wont work either because then projects that don't use the --lib option will get conflicting DOM and Node definitions and will see the error TS2403: Subsequent variable declarations must have the same type. Variable 'console' must be of type 'Console', but here has type 'Console'.

I'm testing out changes to node.d.ts that will work both with and without --lib, and will submit a PR to DefinitelyTyped if I can get it working.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 7, 2016

Looks like a definition bug in nose.d.ts

@mhegazy mhegazy added the @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped label Jul 7, 2016
@mhegazy mhegazy self-assigned this Jul 7, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jul 7, 2016
@yortus
Copy link
Contributor Author

yortus commented Jul 7, 2016

@frogcjn
Copy link

frogcjn commented Aug 15, 2016

How to resolve this problem?

@yortus
Copy link
Contributor Author

yortus commented Aug 15, 2016

@frogcjn if you get your node typings using npm install @types/node, you'll have the updated node.d.ts that includes the Console definitions.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 16, 2016

thanks @yortus

@mhegazy mhegazy closed this as completed Aug 16, 2016
@evmar
Copy link
Contributor

evmar commented Dec 28, 2016

This seems to have caused this bug:
#13204

@gatspy
Copy link

gatspy commented Jul 14, 2017

tsconfig , lib property add "dom"

@coolboygym
Copy link

thanks @gatspy

@coconilu
Copy link

thanks @gatspy ,it works!

@gaochengyidlmu
Copy link

@gatspy thanks

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
Projects
None yet
Development

No branches or pull requests

8 participants