Skip to content

incorrect compilation failure because tsc loads node_modules/@types/**/*.d.ts irrespective of their usage. #11949

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

Closed
reshadi opened this issue Oct 30, 2016 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@reshadi
Copy link

reshadi commented Oct 30, 2016

Hi,

TypeScript Version: 2.0.6

Code

a.ts contains:
console.log(1);

run these commands:
npm install supertest @types/supertest
tsc --module commonjs --target es5 --listFiles a.ts

Expected behavior:

a.ts

Actual behavior:

node_modules/@types/superagent/index.d.ts(83,31): error TS2304: Cannot find name 'Promise'.
%AppData%/npm/node_modules/typescript/lib/lib.d.ts
a.ts
C:/types-bug/node_modules/@types/node/index.d.ts
C:/types-bug/node_modules/@types/superagent/index.d.ts
C:/types-bug/node_modules/@types/supertest/index.d.ts

** Problem **
It looks like the tsc compiler loads node_modules/@types/* */ *.d.ts irrespective of their usage.

I thought that in the node module resolution mode, the behavior of the compiler should be to look for .ts or .d.ts files first in the "node_modules/X" then in the "node_modules/@types/X" only when it sees an "import 'X'" in the code. Instead it looks like tsc loads everything in node_modules/@types first.

One use case that this causes problem is when you have both server and client side code and want to compile the server side to es6 and client to es5.

Thanks.

@aluanhaddad
Copy link
Contributor

Possible duplicate of #11917

@mhegazy
Copy link
Contributor

mhegazy commented Dec 16, 2016

use --types or set types: [] in your tsconfig.json. this will instruct the compiler to load nothing. Please see more documentation at www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 16, 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
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants