ttarnowski/ts-sinon

Install time compilation not playing nice

Closed this issue ยท 5 comments

When attempting to add ts-sinon to an existing project, I got the following error:

yarn add v1.12.3
warning package.json: No license field
warning ../../../../../package.json: No license field
warning @tm.is/readiness@0.0.1-alpha-1: No license field
[1/4] ๐Ÿ”  Resolving packages...
warning ts-sinon > typemoq > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
warning ts-sinon > typemoq > postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.
[2/4] ๐Ÿšš  Fetching packages...
warning Pattern ["uuid@latest"] is trying to unpack in the same destination "/Users/gulli/Library/Caches/Yarn/v4/npm-uuid-3.3.2-1b4af4955eb3077c501c23872fc6513811587131/node_modules/uuid" as pattern ["uuid@^3.3.2"]. This could result in non-deterministic behavior, skipping.
[3/4] ๐Ÿ”—  Linking dependencies...
warning " > superagent-mock@3.7.0" has unmet peer dependency "superagent@^3.6.0".
[4/4] ๐Ÿ“ƒ  Building fresh packages...
[2/2] โข€ ts-sinon
error /...readiness/node_modules/ts-sinon: Command failed.
Exit code: 2
Command: tsc -p .
Arguments: 
Directory: /.../readiness/node_modules/ts-sinon
Output:
../@types/superagent/index.d.ts(30,29): error TS2304: Cannot find name 'Blob'.
../@types/superagent/index.d.ts(118,14): error TS2304: Cannot find name 'XMLHttpRequest'.

Not worth it to me to chase this down, but I suspect this is due to the fact that you are pushing the typescript compilation to install time instead of doing it during prePublishOnly. That would make this package play much nicer with other people's dependencies, and enable you to push a lot of the dependencies to devDependencies (like TypeScript). The more dependencies that are devDependencies for a library like this, the better.

I've tried to move compilation command to prepublishOnly and it breaks the library (compilation has not been executed during publishing at all). Although I've managed to move most of the dependencies to devDependencies. Regarding your issue I wasn't able to reproduce that - for me everything seems to work well with yarn (install, adding dependency, adding dev dependency from the command line)

I ran into this with a project using @types/jest.
Updating this lib to 1.0.16 and @types/jest to 24.x will fail the compile step of ts-sinon on install.

 "@types/jest": "24.0.9",
 "ts-sinon": "1.0.16",

These versions work fine together

 "@types/jest": "23.3.13",
    "ts-sinon": "1.0.12",

My guess is the compile step this lib does when installed is pulling in types not meant to compile against and could fail against them.

I am afraid it is caused by the conflict in types definitions of jest - test functions (such as "before", "beforeEach", "describe", etc.) are not defined within the namespace in jest\index.d.ts. You will have to open an issue for the jest types maintainer to fix that conflict (https://github.com/DefinitelyTyped/DefinitelyTyped)

@ttarnowski, it happened to me as well and I don't use @types/jest.
From what I saw it's because the tsconfig is missing the --lib dom.
I cloned the repo, added it and it worked

I have updated the library to include dom and es2015 in the lib.