hookrouter
hookrouter copied to clipboard
Typescript error: index.d.ts file is missing
After upgrading the library from 1.2.3 to 1.2.5 I started to see hookrouter/dist/index.d.ts is not a module
error. I think it's because *.d.ts
files are not included with hookrouter/dist folder anymore.
I believe it has to do with the fact that they are, in fact, included.
As you can see from looking at the package contents:
$ npm pack hookrouter@latest --dry-run
npm notice
npm notice package: [email protected]
npm notice === Tarball Contents ===
npm notice 804B dist/_testHelper.js
npm notice 6.1kB dist/controlledInterceptor.js
npm notice 4.4kB dist/index.js
npm notice 6.3kB dist/interceptor.js
npm notice 799B dist/isNode.js
npm notice 6.1kB dist/Link.js
npm notice 11.5kB dist/queryParams.js
npm notice 2.3kB dist/redirect.js
npm notice 44.7kB dist/router.js
npm notice 2.4kB dist/routes.js
npm notice 1.3kB dist/routes.test.js
npm notice 607B dist/test.js
npm notice 3.0kB dist/title.js
npm notice 1.4kB package.json
npm notice 282B dist/_testHelper.d.ts.map
npm notice 415B dist/_testHelper.js.map
npm notice 104B dist/index.d.ts.map
npm notice 102B dist/index.js.map
npm notice 675B dist/routes.d.ts.map
npm notice 1.8kB dist/routes.js.map
npm notice 116B dist/routes.test.d.ts.map
npm notice 1.3kB dist/routes.test.js.map
npm notice 133B dist/test.d.ts.map
npm notice 439B dist/test.js.map
npm notice 1.5kB README.md
npm notice 300B dist/_testHelper.d.ts
npm notice 35B dist/index.d.ts
npm notice 808B dist/routes.d.ts
npm notice 53B dist/routes.test.d.ts
npm notice 80B dist/test.d.ts
npm notice === Tarball Details ===
npm notice name: hookrouter
npm notice version: 1.2.5
npm notice filename: hookrouter-1.2.5.tgz
npm notice package size: 32.6 kB
npm notice unpacked size: 100.0 kB
npm notice shasum: ea1b88fd9f6a48816b17145bfb2b38dfc93df21e
npm notice integrity: sha512-9OLve2u+JZDCO[...]UrZ4hUYoK0ezw==
npm notice total files: 30
Compare that with the last release:
$ npm pack [email protected] --dry-run
npm notice
npm notice package: [email protected]
npm notice === Tarball Contents ===
npm notice 1.4kB package.json
npm notice 1.5kB README.md
npm notice 6.1kB dist/controlledInterceptor.js
npm notice 4.4kB dist/index.js
npm notice 6.3kB dist/interceptor.js
npm notice 799B dist/isNode.js
npm notice 5.9kB dist/Link.js
npm notice 11.5kB dist/queryParams.js
npm notice 2.3kB dist/redirect.js
npm notice 44.7kB dist/router.js
npm notice 3.0kB dist/title.js
npm notice === Tarball Details ===
npm notice name: hookrouter
npm notice version: 1.2.3
npm notice filename: hookrouter-1.2.3.tgz
npm notice package size: 28.9 kB
npm notice unpacked size: 88.0 kB
npm notice shasum: a65599a1be376b51734caf7c4f7f8aba59bb2c77
npm notice integrity: sha512-n0mqEBGgXIxYR[...]zexTBfo//tq2Q==
npm notice total files: 11
Looking at the *.d.ts
files, we can see they are basically empty type definitions. Deleting them from your node_modules
solves the issue, as the TypeScript compiler now correctly gets the types from the @types/hookrouter
package. I believe @Paratron should just re-release without including these files, although he has expressed not wanting to support TypeScript.
As a temporary workaround, you can add these lines to .yarnclean
and perform yarn autoclean --force
:
hookrouter/dist/index.d.ts
hookrouter/dist/index.d.ts.map
Thanks for the awesome project by the way, we use it every day in production here and it's been working great. 🎉
I honestly have no idea how those files ended up there. I did not use TS to create hookrouter, so no idea what generated them 🤔
However - I am working on v2.0 in a separate branch of this repo - this time even based on TS 😁🤫
Hey @Paratron,
If you will look at the build output for version 1.2.5, then you will see that it includes code from version 2.0. based on TS. You have somehow created wrong build with code from branch v2-ts. See at routes.js, routes.d.ts, index.js, index.d.ts (which is actually empty)...
It would be great if you can just publish fixed build for 1.2.5 (as 1.2.6) without changes from branch v2-ts
Hi.
Yes, a new version without those files would be great because 1.2.5 AND 1.2.4 are unusable with typescript without removing those files manually. As a new user to this library I was surprised and had to downgrade to 1.2.3. yarn autoclean is a great tip but it works only for yarn users.
@mbaroukh
Yes, a new version without those files would be great because 1.2.5 AND 1.2.4 are unusable with typescript without removing those files manually.
If you're using yarn, @pbondoer 's solution works. You can add that to your scripts that run and not have to do it manually. Not sure if npm (my preferred package manager anyway) has a similar command. I'm currently on a project using yarn....
Hacky workaround for npm using a postinstall script:
# package.json
{
"scripts": {
"cleanup-hookrouter-types": "rm -f node_modules/hookrouter/dist/index.d.ts* # See https://github.com/Paratron/hookrouter/issues/147",
"postinstall": "npm run cleanup-hookrouter-types"
}
}
Hi guys, I've recently upgraded from 1.2.3 to 1.2.5 and getting the same issue here. Is the solution provided by @pbondoer one that is usable in a build/deploy (CI/CD) environment?
UPDATE: I attempted the .yarnclean and it seems to work locally. I'll give this a go by running in our CI environment. I hadn't used yarn clean before, didn't realise it'll run on every yarn install. Cheers.
Thanks for the workaround. I'm surprised to see the project basically abandoned. Wish I had time to contribute. Thanks for all the fish