Help with npm peerDependencies
Hi π
I am using an npm library that has
@sinclair/typebox
listed under peerDependencies
.
It gives the following runtime error whenever I import/use the library:
I tried to add this peer to my imports
in deno.jsonc
, but the error persists.
I've read some comments claiming that peer dependencies work. am I missing something?
10 Replies
Based on the documentation, Deno has added support for npm packages, including those with peer dependencies. However, the error you're encountering suggests that the module '@sinclair/typebox/value' cannot be found.
Here are a few things you could try:
1. Check the version of the peer dependency: Ensure that the version of '@sinclair/typebox' listed under
peerDependencies
in the npm library's package.json
file is compatible with the version you're using.
2. Check the import specifier: Make sure you're using the correct import specifier for '@sinclair/typebox'. In Deno, you should use the npm specifier format, which looks like this: npm:@sinclair/typebox@version
.
3. Check your deno.jsonc
file: Ensure that you've correctly added '@sinclair/typebox' to the imports
field in your deno.jsonc
file. The entry should look something like this:
4. Check for type errors: If the npm library doesn't distribute types, you might need to specify the corresponding @types
package using a @deno-types
directive above the import. However, this is usually not necessary for runtime errors.
If you've checked all of these and the issue persists, it might be a limitation or bug in Deno's npm package support. In that case, I would recommend reporting the issue to the Deno team for further assistance.Hi @bogeychan, could you check if issue persists if you add
import "npm:@sinclair/typebox@versionfrompeer"
At the very start of your app?
Imports field in deno.json is more like a mapping for aliases for things that will be imported (import map), they aren't importing anything alone@bogeychan Can you share which dependency uses
@sinclair/typebox
as a peerDependency?Hi all π ,
@Danielduel, that makes it kinda worse...
@marvinh., the dependency is
npm:elysia@0.7.29
---
you can reproduce it like:
running the following commands works 50% of the time (checkout the screenshots): no change to code
doesn't work with or without --node-modules-dir
idk why but sometimes deno decides to download the elysia
dependency multiple times (with _1
) suffix (checkout the screenshots). therefore some dependencies use/reference elysia_01
as it's peer). that's bad because both elysia
's reference the same @sinclair/typebox
package and it throws the error Duplicate type kind 'Files' detected
because its executed twice, ... https://github.com/elysiajs/elysia/blob/757357f28749674844fc848e4ddd715134f7714f/src/type-system.ts#L144
the dependency tree looks something like this:
- main.ts
- elysia
- @sinclair/typebox (peer)
- @elysiajs/cors
- elysia (peer)
- @elysiajs/html
- elysia (peer)
- @elysiajs/bearer
- elysia (peer)
- @elysiajs/swagger
- elysia (peer)GitHub
elysia/src/type-system.ts at 757357f28749674844fc848e4ddd715134f771...
Ergonomic Framework for Humans. Contribute to elysiajs/elysia development by creating an account on GitHub.
That sounds like a bug. Filed an issue here https://github.com/denoland/deno/issues/21394
see my comment here with a workaround: https://github.com/denoland/deno/issues/21394#issuecomment-1833889464
ooh, that makes sense, it works! thanks everyone <:hooray_deno:1035517542200004688> <:chun_happy:1076036980334415882>
We should file an issue on their tracker to make them aware of the missing depedency declaration
i'm not sure about that in this case. I feel like Deno should just be able to figure it out
this dependency resolution should work if deno wanna be fully compatible with node.js.
in case you wanna try it out for yourself:
I'm fine with the workaround, since the polyfills are experimental anyway