Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing NPM dependency "restify" results in an error #26394

Closed
jonha892 opened this issue Oct 18, 2024 · 5 comments · Fixed by #26401
Closed

Importing NPM dependency "restify" results in an error #26394

jonha892 opened this issue Oct 18, 2024 · 5 comments · Fixed by #26401

Comments

@jonha892
Copy link

Hi,
I wanted to try deno but it fails right at the start when trying to use a "npm" dependency.

I set up a very basic projekt like this:

mkdir deno_test
cd deno_test
deno init
deno add npm:restify

I modified the main.ts like this:

import * as restify from "npm:restify";

const server = restify.createServer({
  name: "myapp",
  version: "1.0.0",
});

server.get("/", (req, res, next) => {
  res.send("hello world from deno");
  next();
});

server.listen(8080, () => {
  console.log("%s listening at %s", server.name, server.url);
});

And started the server with deno run -A main.ts

However, I get an error that indicated that there is an error with a peer dependency.
The same code works however when I set it up with node and tsx.

So far i also reproduced it on two different machines.

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'methods')
    at Object.<anonymous> (file:///home/jonas/.cache/deno/npm/registry.npmjs.org/http-deceiver/1.2.7/lib/deceiver.js:23:24)
    at Object.<anonymous> (file:///home/jonas/.cache/deno/npm/registry.npmjs.org/http-deceiver/1.2.7/lib/deceiver.js:252:4)
    at Module._compile (node:module:748:34)
    at Object.Module._extensions..js (node:module:767:10)
    at Module.load (node:module:665:32)
    at Function.Module._load (node:module:537:12)
    at Module.require (node:module:684:19)
    at require (node:module:808:16)
    at Object.<anonymous> (file:///home/jonas/.cache/deno/npm/registry.npmjs.org/spdy/4.0.2/lib/spdy/handle.js:5:20)
    at Object.<anonymous> (file:///home/jonas/.cache/deno/npm/registry.npmjs.org/spdy/4.0.2/lib/spdy/handle.js:249:4)

Version:
deno 2.0.2 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2

@nathanwhit
Copy link
Member

The cause is that http-deceiver uses a soon to-be deprecated API that accesses node's C++ internals.

@jonha892
Copy link
Author

Ok, so there is no workaround?

The "full node & npm compatability" is just a marketing ploy?

@szmarczak
Copy link

szmarczak commented Oct 18, 2024

The "full node & npm compatability" is just a marketing ploy?

Correct. They're liars. They should be ashamed of using that marketing tactic. Reminds me of Electron similarly marketing Node.js compatibility (in addition Electron closed legitimate bug reports with full repro, didn't even bother checking the repro and I got banned there after reprimanding them). I wish Deno doesn't go this route.

@bartlomieju
Copy link
Member

Ok, so there is no workaround?

The "full node & npm compatability" is just a marketing ploy?

This issue should be now fixed, you can try it out by upgrading to latest canary with deno upgrade canary before this fix makes its way to the Deno v2.0.3 release next week.

@jonha892
Copy link
Author

Alright, thank you for the quick fix.
I checked, and it works now.

I hope it's a one time thing that the node dependency doesn't work.
And to be fair, The dependency doesn't work in Bun and they haven't fixed it for a year now.

Still sad that deno doesn't seem to be 100% compatible with node. I wish they/you would have been more transparent in that regard. I cant remember incompatabilities being mentioned in the 2 hour announcement video. Additionally the recent teaser states "full node & npm compatability".

I'd have a hard time recommending deno in projects for clients when there is a chance of incompatible libraries.
For me, the greatest use case for deno is the simplified and unified tooling.
But we already know how to use and configure prettier, typescript etc.

So we'd trade problems we know how to solve (existing tooling) to problems we don't know how to solve (incompatible libraries).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants