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

How to block typescript 2.0 from walking up all parent directories while resolving modules? #13992

Closed
zakimaksyutov opened this issue Feb 10, 2017 · 9 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@zakimaksyutov
Copy link
Member

Upgraded to Typescript 2.0 (2.1.6) and it started giving "Duplicate identifier" errors. After taking a closer look it turned out that Typescript started importing @types from all upper directories (essentially other projects).

What should be the configuration to let Typescript to ignore upper node_modules?

src
└── node_modules << *** how to ignore it? ***
└── @types

└── my.app << *** how to build this folder and down only? ***
└── node_modules
└── @types

EDIT: Here is an example of error I'm getting:

typings/globals/mocha/index.d.ts(30,13): error TS2300: Duplicate identifier 'describe'. ../../../node_modules/@types/jasmine/index.d.ts(9,18): error TS2300: Duplicate identifier 'describe'.

listFiles: true shows @types/jasmine being imported from upper folder:

C:/src///<my.app>/typings/globals/mocha/index.d.ts
C:/src/node_modules/@types/jasmine/index.d.ts
If I rename upper node_modules folder then build succeeds.

http://stackoverflow.com/questions/42150920/how-to-block-typescript-2-0-from-walking-up-all-parent-directories-while-resolvi

@mhegazy
Copy link
Contributor

mhegazy commented Feb 10, 2017

use --types node or set "types" : ["node"]. this tells the compile to only include @types\node in your compilation.

use --types or set "types": [] to avoid including any of them.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Feb 10, 2017
@zakimaksyutov
Copy link
Member Author

Thank you!

Used "typeRoots": ["./typings"] and it resulted in

error TS2688: Cannot find type definition file for 'globals'.

Specifying --types didn't fix this error.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 11, 2017

typeRoots change where the system is looking for packages. unless you want to include files from typings, do not change it. you can find more information about types and typeroots at http://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types

@blakeembrey
Copy link
Contributor

@zakimaksyutov Typings puts things under two directories (globals vs modules) - try with typings/globals if you're using Typings.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@jurosh
Copy link

jurosh commented Apr 26, 2018

Is there real solution ? I've tested all suggested options but with no luck.. compilation failed because in parent ../../node_modules is another project which will duplicate all typings...

@evil-shrike
Copy link

I had the same issue:
given a project with tsconfig and inside it there's a folder with a completely separated ts-project with its own tsconfig. it didn't want to compile as tsc was importing node_modules/@types from parent folder.
Settings "types" : ["node"] in that tsconfig.json did help.

@rjmunro
Copy link

rjmunro commented May 3, 2018

@mhegazy Why did you close this? There is no actual solution, just a couple of suggested hacks. It is a valid feature request, if not an outright bug.

@peterjwest
Copy link

As far as I know, using "typeRoots": ["./node_modules/@types"] should prevent typescript looking in parent directories, but it doesn't solve the problem for me.

@rjmunro
Copy link

rjmunro commented May 3, 2018

Here's the stupid fix we are now using:

  "scripts": {
    "build": "if [ -d ../node_modules ]; then mv ../node_modules ../node_modules_tmp; fi; <normal build command here>; if [ -d ../node_modules_tmp ]; then mv ../node_modules_tmp ../node_modules; fi",
  }

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

7 participants