D
Deno

help

Help with npm peerDependencies

Bbogeychan11/24/2023
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:
Uncaught Error: Cannot find module '@sinclair/typebox/value'
Uncaught Error: Cannot find module '@sinclair/typebox/value'
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?
deno 1.38.3 (release, x86_64-unknown-linux-gnu)
v8 12.0.267.1
typescript 5.2.2
deno 1.38.3 (release, x86_64-unknown-linux-gnu)
v8 12.0.267.1
typescript 5.2.2
DAHDeno AI Helper11/24/2023
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:
{
"imports": {
"@sinclair/typebox/": "npm:@sinclair/typebox@version/"
}
}
{
"imports": {
"@sinclair/typebox/": "npm:@sinclair/typebox@version/"
}
}
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.
DDanielduel11/29/2023
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
Mmarvinh.11/29/2023
@bogeychan Can you share which dependency uses @sinclair/typebox as a peerDependency?
Bbogeychan11/30/2023
Hi all 👋 , @Danielduel, that makes it kinda worse... @marvinh., the dependency is npm:elysia@0.7.29 --- you can reproduce it like:
// main.ts
import 'npm:@bogeychan/elysia-polyfills/deno/index.js';

import 'npm:@sinclair/typebox@0.31.17';

import { cors } from 'npm:@elysiajs/cors@0.7.2';
import { html } from 'npm:@elysiajs/html@0.7.3';
import { bearer } from 'npm:@elysiajs/bearer@0.7.0';
import { swagger } from 'npm:@elysiajs/swagger@0.7.4';

import { Elysia } from 'npm:elysia@0.7.29';

new Elysia()
.use(cors())
.use(html())
.use(bearer())
.use(swagger())
.get('/', () => ({ hello: 'Deno👋' }))
.listen(8080);
// main.ts
import 'npm:@bogeychan/elysia-polyfills/deno/index.js';

import 'npm:@sinclair/typebox@0.31.17';

import { cors } from 'npm:@elysiajs/cors@0.7.2';
import { html } from 'npm:@elysiajs/html@0.7.3';
import { bearer } from 'npm:@elysiajs/bearer@0.7.0';
import { swagger } from 'npm:@elysiajs/swagger@0.7.4';

import { Elysia } from 'npm:elysia@0.7.29';

new Elysia()
.use(cors())
.use(html())
.use(bearer())
.use(swagger())
.get('/', () => ({ hello: 'Deno👋' }))
.listen(8080);
running the following commands works 50% of the time (checkout the screenshots): no change to code
rm -fr ~/.cache/deno/ deno.lock node_modules/
deno run --node-modules-dir --allow-net main.ts
rm -fr ~/.cache/deno/ deno.lock node_modules/
deno run --node-modules-dir --allow-net main.ts
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.
No description
No description
Mmarvinh.11/30/2023
That sounds like a bug. Filed an issue here https://github.com/denoland/deno/issues/21394
Ddsherret11/30/2023
Bbogeychan11/30/2023
ooh, that makes sense, it works! thanks everyone <:hooray_deno:1035517542200004688> <:chun_happy:1076036980334415882>
Mmarvinh.11/30/2023
We should file an issue on their tracker to make them aware of the missing depedency declaration
Ddsherret11/30/2023
i'm not sure about that in this case. I feel like Deno should just be able to figure it out
Bbogeychan11/30/2023
this dependency resolution should work if deno wanna be fully compatible with node.js. in case you wanna try it out for yourself:
// main.js
import '@bogeychan/elysia-polyfills/node/index.js';

import { cors } from '@elysiajs/cors';
import { html } from '@elysiajs/html';
import { bearer } from '@elysiajs/bearer';
import { swagger } from '@elysiajs/swagger';

import { Elysia } from 'elysia';

const app = new Elysia()
.use(cors())
.use(html())
.use(bearer())
.use(swagger())
.get('/', () => ({ hello: 'Node.js👋' }))
.listen(8080);

console.log('Listening on http://localhost:8080');
// main.js
import '@bogeychan/elysia-polyfills/node/index.js';

import { cors } from '@elysiajs/cors';
import { html } from '@elysiajs/html';
import { bearer } from '@elysiajs/bearer';
import { swagger } from '@elysiajs/swagger';

import { Elysia } from 'elysia';

const app = new Elysia()
.use(cors())
.use(html())
.use(bearer())
.use(swagger())
.get('/', () => ({ hello: 'Node.js👋' }))
.listen(8080);

console.log('Listening on http://localhost:8080');
// package.json
{
"private": true,
"type": "module",
"main": "main.js",
"dependencies": {
"@bogeychan/elysia-polyfills": "0.6.1",
"@elysiajs/cors": "0.7.2",
"@elysiajs/html": "0.7.3",
"@elysiajs/bearer": "0.7.0",
"@elysiajs/swagger": "0.7.4",
"elysia": "0.7.29"
}
}
// package.json
{
"private": true,
"type": "module",
"main": "main.js",
"dependencies": {
"@bogeychan/elysia-polyfills": "0.6.1",
"@elysiajs/cors": "0.7.2",
"@elysiajs/html": "0.7.3",
"@elysiajs/bearer": "0.7.0",
"@elysiajs/swagger": "0.7.4",
"elysia": "0.7.29"
}
}
npm i && node . # v18.16.0
npm i && node . # v18.16.0
I'm fine with the workaround, since the polyfills are experimental anyway

Looking for more? Join the community!

Recommended Posts
AWS Lambda configHow do i set permissions in deno for aws lambda. Like --allow-env etcMigrating from EventEmitter…Hi! I've got some legacy code that depends on `node:events` 's `EventEmitter` class, specifically itusing flexsearchso flexsearch has a index.d.ts thats broken and hasn't been touched in 2ish years and instead you shDoes Deno third party modules support to wrap NPM in importmapHere is my first module: https://deno.land/x/lume_fluent@1.0.0-alpha My importmap for the module isHelp using DenoMaileri'm trying to use it but i get Deno is not defined when i try to send the email, any tips? how wouldDebug all tests in VSCodeHi everyone. I was hoping to use the equivalent of "deno test" in such a way that I can set a breakMost complete Deno Rust runtime?I’m trying to embed the Deno runtime into my Rust program. I’m looking for the most “complete” Deno Language server crashing in VSC outside of deno projectsHow to write a new project template scriptHey, I've written a small game engine to create text adventures in Deno. The resulting project is a Seamlessly include TailwindcssIs there a recommended way of achieving this at the moment? What is the cleneast way of including tatidy up `deno.lock`Hey, is there something like `go mod tidy` (https://golangbyexample.com/go-mod-tidy/) in Deno? The bSyntaxError on Web3 packageI'm trying to use this module in my project https://deno.land/x/web3@v0.11.1 and i'm using the code how to document oak apiWhat’s the best way to document an oak api. Like swagger or some kind of thatweb based cmsIs there any web based cms system like word press based on deno or fresh?Minimal code for Preact SSRWhat's the actual code to do some Preact SSR with Deno? For example something simple like a counterHow to use recent Tensorflow.JS? TF from deno.land/x/tensorflow@v0.21 appears to work, but it's oldI've only tried the TF package from deno.land/x/tensorflow@v0.21 with the readme page example. I'm hDeno Deploy isolate startup timeis this startup time normal? https://media.discordapp.net/attachments/936130919163641856/11757670644Deno KV equivalent of 'returning'hello, in sqlite there is a way to get the new value set on an upsert like so insert into cCan't use npm package: Uncaught (in promise) TypeError: Could not resolve 'preact/hooks'I get this error when trying to import the Preact version of Auto-animate in Fresh https://auto-animLeaking resources from inbound HTTP connections in testsAnyone have any ideas why I would be getting the following error. I'm using an oak server that is st