Immer: v1.9.0 doesn't include the typescript declarations anymore but "types" prop in package.json is still set to "./dist/immer.d.ts"

Created on 16 Dec 2018  路  9Comments  路  Source: immerjs/immer

The issue is self-explanatory.

So if you go with typescript you will get the following errors with v1.9.0:

error TS7016: Could not find a declaration file for module 'immer'
...
Try `npm install @types/immer` if it exists or add a new declaration (.d.ts) file containing `declare module 'immer';`
bug released

Most helpful comment

:tada: This issue has been resolved in version 1.9.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

All 9 comments

For me I don't get an error, but typings don't work at all. Everything is any. (But this may be, because I use allowSyntheticDefaultImports: true and noImplicitAny: false)

$ ls node_modules/immer/*
node_modules/immer/LICENSE  node_modules/immer/readme.md
node_modules/immer/package.json

node_modules/immer/dist:
immer.js        immer.module.js     immer.umd.js
immer.js.map        immer.module.js.map immer.umd.js.map

No d.ts file(s) with 1.9.0, as you can see.

I found the issue. A patch will be out shortly.

Does anyone know if we can prevent a mistake like this in the future? I'm surprised that tsc doesn't fail when the typings field in package.json is pointing to a non-existent path.

edit: I'll just add an existence check to Travis' deploy stage.

How about just adding a simple test somewhere, that reads types from package.json and checks if the file exists?

How about just adding a simple test somewhere, that reads types from package.json and checks if the file exists?

I think the more reliable approach would be in running the simplest test written in typescript with the strict compilation mode enabled (which is by the way default option of executing tsc --init command, and I'm happy that it's). This test will need to be executed on ./dist fodler, ie be placed to the end of the build pipeline (build npm script), so that would be a kind of e2e test. So if such test fails we then get error exit code and so no npm pubslishing is supposed to happen. I can look into this and propose a PR.

@vladimiry No need to go do that, I've found a simpler solution. We can just import ../dist/immer.js instead of ../src/index.js inside the TypeScript test. See here: https://github.com/mweststrate/immer/pull/269/commits/1b95ea9543caa7c70989796d47fc739cd9395d76

@aleclarson

We can just import ../dist/immer.js instead of ../src/index.js inside the TypeScript test. See here: 1b95ea9

This is exactly what I meant. But I'd suggest enabling strict compilation option in this config.

Okay, the only thing holding this up is that yarn test:flow does not fail when dist/immer.js.flow is missing.

edit: Fixed by 4d2798cb3b424980b02e82d4316e8999f3e2a628

:tada: This issue has been resolved in version 1.9.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Thanks for the assistance @vladimiry and @benneq

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mweststrate picture mweststrate  路  4Comments

TrueWill picture TrueWill  路  4Comments

DanielRuf picture DanielRuf  路  5Comments

dfadev picture dfadev  路  6Comments

cakoose picture cakoose  路  6Comments