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

Cannot find type definition file for 'chai' #2112

Closed
jefbarn opened this issue Nov 6, 2016 · 22 comments · Fixed by #2120
Closed

Cannot find type definition file for 'chai' #2112

jefbarn opened this issue Nov 6, 2016 · 22 comments · Fixed by #2120

Comments

@jefbarn
Copy link

jefbarn commented Nov 6, 2016

Edit: fixed in rc4

New in rc.2:

C:\projects\dayapp\node_modules\rxjs\observable\PairsObservable.d.ts
Error:(1, 1) TS2688: Cannot find type definition file for 'chai'.
C:\projects\dayapp\node_modules\rxjs\observable\dom\AjaxObservable.d.ts
Error:(1, 1) TS2688: Cannot find type definition file for 'chai'.

workaround

npm install --save-dev @types/chai
@kwonoj
Copy link
Member

kwonoj commented Nov 6, 2016

Some of transpiled results has unexpected type references,

/// <reference types="chai" />
import { Observable } from '../../Observable';
import { Subscriber } from '../../Subscriber';
import { TeardownLogic } from '../../Subscripti...'

while those file does not uses those type references. Seems it's known issue of TS, updated compiler to latest dev to avoid this.

@Skuriles
Copy link

Skuriles commented Nov 8, 2016

Update to TS 2.1 Dev didn't help. Used 'next' version of TS in package.json.
Gone back to rxjs 5 rc1 and using TS latest (2.0.8) is working so far.
Waiting for fix.

@iamdanfox
Copy link

iamdanfox commented Nov 8, 2016

I don't have a solution to this yet, but I think the problem is caused by Typescript's automatic @types detection of node_modules/@types/chai leaking into prod code, caused after switching away from Typings.

1. Local repro

After running npm run build_es6 (with master at 922d04e), I can see four .d.ts files have the problematic line:

/// <reference types="chai" />

screen shot 2016-11-08 at 13 21 29

2. Minimal example case

src/util/assign.ts is a particularly small source file that ends up with the problematic chai dependency. The problem goes away if we remove any mention of Object from the file - specifically, I changed the signature of assignImpl from:

export function assignImpl(target: Object, ...sources: Object[]) {

to

export function assignImpl(target: any, ...sources: any[]) {

(The three other files also have mentions of Object).

It seems that the @types/chai package that is installed as part of 5.0.0-rc2 mentions Object at line 414:

interface Object {
    should: Chai.Assertion;
}

3. Narrow down the cause

Between 5.0.0-rc.1 and 5.0.0-rc.2, the dist output may have been affected by:

  • rxjs switching from using npm install to yarn
  • switching from Typings to using the npm @types/ packages. (before, after)

Note, the version of chai never changed from ^3.5.0 and the content of the chai typings file isn't the problem. If I copy typings/globals/chai/index.d.ts from 5.0.0-rc.1 and paste it into node_modules/@types/chai/index.d.ts, I still get four unwanted chai references in the built dist.

I can't see any evidence that yarn is the problem here, it seems much more likely that switching from Typings to the new @types modules caused the problem. Despite having two tsconfig.json files (one for main, one for spec), it seems like the typescript compiler is happily pulling node_modules/@types/chai into main code (when it should only be pulled into spec code).

4. Solutions

Ideally, if we could switch off tsc's node_modules/@types resolution for the main dist, I think this would solve everything. (Not sure if typescript supports this, or is even aware this can be a problem). Alternatively, rxjs could just switch back to using Typings instead of the new npm modules.

I'm sure there are lots of other possible solutions, I defer to the rxjs team to pick a sensible one!

@Skuriles
Copy link

Skuriles commented Nov 8, 2016

JFYI:
I'm actually using some @types (e.g. highcharts , jquery) and this is working with my above mentioned combination (rc1 + TS 2.0.8)

@kwonoj
Copy link
Member

kwonoj commented Nov 8, 2016

@iamdanfox yes, I suspect it's related to microsoft/TypeScript#11948
@Skuriles it'll not be resolved by consumer side TSC version, since type definition is already published includes those references.

I'm seeing couple of options here

@karlbohlmark
Copy link

Why not just publish a new version to npm that fixes the issue while waiting for the fix in TS?

@kwonoj
Copy link
Member

kwonoj commented Nov 9, 2016

@karlbohlmark I think we will.

@karlbohlmark
Copy link

@kwonoj Great, thanks!

@jayphelps
Copy link
Member

5.0.0-rc3 was just published, which solved this. If not, please reopen!

@tetsuharuohzeki
Copy link
Contributor

@jayphelps

I confirm this problem is not resolved in 5.0.0-rc3.
We need to republish it.

Environment

Problems

  1. These files contains /// <reference types="chai" />
    • observable/PairsObservable.d.ts
    • observable/dom/AjaxObservable.d.ts
  2. So TypeScript compilers still requires @types/chai.

@jayphelps jayphelps reopened this Nov 15, 2016
@jayphelps
Copy link
Member

@kwonoj any guesses?

@kwonoj
Copy link
Member

kwonoj commented Nov 15, 2016

@jayphelps is it possible to confirm node_modules have remaining @types packages when pack new package? if it does, force clear node_modules then retry npm pack.

@Skuriles
Copy link

I can confirm this error in RC3. Still

PairsObservable.d.ts(1,1): error TS2688: Cannot find type definition file for 'chai'.
AjaxObservable.d.ts(1,1): error TS2688: Cannot find type definition file for 'chai'.

error on compile.

@jasonholmberg
Copy link

I can also confirm that this error still exists in RC3 after clearing node_modules

[08:26:37] [tsc] > node_modules/rxjs/observable/PairsObservable.d.ts(1,1): error TS2688: Cannot find type definition file for 'chai'.
[08:26:37] [tsc] > node_modules/rxjs/observable/dom/AjaxObservable.d.ts(1,1): error TS2688: Cannot find type definition file for 'chai'.

@jayphelps
Copy link
Member

jayphelps commented Nov 15, 2016

I'm still not seeing these /// <reference types="chai" /> references when I build locally...Can someone else fetch the latest, build, and confirm they do or do not see /// <reference types="chai" /> in observable/PairsObservable.d.ts or observable/dom/AjaxObservable.d.ts?

That is, I DO see them in the npm package tarball, but not when I build locally.

@kwonoj
Copy link
Member

kwonoj commented Nov 15, 2016

@jayphelps as commented above, I am currently suspect when packing current one there was remaining types module in local node_modules, which makes package have old behavior and explains why local build works. To confirm this, may need check machine being used for package and check those modules are remaining, then republish new package as needed if it's confirmed in those way. (Just fyi, local build also works for me after force clear node_modules and reinstall)

@jayphelps
Copy link
Member

@kwonoj sorry, I misunderstood what you meant in your original comment. I suspect the same thing. I've pinged @Blesh.

@zackarychapple
Copy link

I can confirm this is happening with rc.3 in a fresh install.
image

@endel
Copy link

endel commented Nov 17, 2016

Confirmed. Still happening using latest TypeScript version. Previously reported on this issue microsoft/TypeScript#11948

@kwonoj
Copy link
Member

kwonoj commented Nov 17, 2016

@here it is known and reproducible issue with latest package and currently expected to resolve in next package publish.

tobymurray added a commit to tobymurray/recipe-book that referenced this issue Nov 20, 2016
@kwonoj
Copy link
Member

kwonoj commented Nov 20, 2016

I believe this issue is fixed with latest rc.4 package publish.

@kwonoj kwonoj closed this as completed Nov 20, 2016
michaeljota pushed a commit to michaeljota/angular2-ultimate-starter that referenced this issue Nov 20, 2016
* Fix an issue with `chai` `@types`. ref: ReactiveX/rxjs#2112
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
10 participants