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

Compiler Error on Empty file: Cannot find name 'Promise'. #11864

Closed
aozgaa opened this issue Oct 26, 2016 · 3 comments
Closed

Compiler Error on Empty file: Cannot find name 'Promise'. #11864

aozgaa opened this issue Oct 26, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@aozgaa
Copy link
Contributor

aozgaa commented Oct 26, 2016

TypeScript Version: master, commit 8ad68ad

Reproduced on Win10 and Ubuntu 16.04.

Code

Note: this initially appeared with nonempty files, but I tried to minimize the repro.

  1. Create an empty file called "empty.ts" in a folder without tsconfig.json or anything else

  2. rm -rf node_modules in the typescript repo

  3. npm install and (in case you didn't have it before) npm install -g jake

  4. build typescript with 'jake local'

  5. Run node /path/to/built/local/tsc.js /path/to/anything.ts from the TypeScript repo folder.

Expected behavior:

Compiles successfully.

Actual behavior:

Fails with the following errors:

node_modules/@types/del/index.d.ts(10,40): error TS2304: Cannot find name 'Promise'.
node_modules/@types/del/index.d.ts(11,62): error TS2304: Cannot find name 'Promise'.
node_modules/@types/del/index.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
node_modules/@types/del/index.d.ts(14,65): error TS2304: Cannot find name 'Promise'.
@aozgaa aozgaa added Bug A bug in TypeScript and removed Bug A bug in TypeScript labels Oct 26, 2016
@aozgaa
Copy link
Contributor Author

aozgaa commented Oct 26, 2016

The problem was caused by some contents of the node_modules folder in the TypeScript repo folder.

If we don't build by specifying a tsconfig.json file at the command-line, it appears node modules are automatically loaded by walking up from the working directory, following the rules on the module resolution page.
It's unclear to me why, philosophically, any modules are searched for at all.

Building from a path that doesn't include the TypeScript repo prevents us from loading the problematic node module.

Workarounds:

  1. call tsc.js from a working directory that doesn't include the offending node_modules along the path. Ie: don't issue the build command while in the TypeScript repo.

  2. Add a tsconfig.json file which includes the single file, and build by pointing towards that.

  3. Add the compiler flag --lib es6 to the commandline operation so promises are available.

This may be related to #11803.

@aozgaa
Copy link
Contributor Author

aozgaa commented Oct 26, 2016

Any thoughts on proper behavior here / why we do what we do in the status quo, @mhegazy, @billti, @vladima ?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 26, 2016

the node_modules@types are automatically included. some of them depend on ES6 objects. so you get this error. I plan to discuss this in the next design meeting under #11396

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 26, 2016
@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants