deno: `deno compile` cannot resolve npm modules

It seems that deno compile has trouble compiling scripts using npm modules.

Given the following script:

// main.ts
import express from "npm:express@4.18";
const app = express();

app.get("/", function (req, res) {
  res.send("Hello World");
});

app.listen(3000);
console.log("listening on http://localhost:3000/");

When I do

deno compile main.ts

I get the following error:

Check file:///Users/fred/Code/Own/deno/main.ts
error: Uncaught Error: could not find npm package directory for 'express@4.18'
    at <anonymous> (deno:cli/tsc/99_main_compiler.js:616:28)

I use the following deno version:

deno 1.28.0 (release, aarch64-apple-darwin)
v8 10.9.194.1
typescript 4.8.3

On OSX version 12.6

Using deno run on the same script works, as does deno compile for scripts that do not use npm packages.

The error also happens when using npm packages other than express

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 24
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I started actual work on this one yesterday. Just doing the preliminary refactors to make it easier.

@dsherret is working on this feature.

+1 for npm support in Deno compile.

Ah, indeed, seems I overlooked that part in the release notes ๐Ÿ˜…

In any case, congrats and thanks for this release ๐Ÿ‘

Okay, need to eat my hat. Want to get @apollo/server@4.6.0 up and running with express. Easy port for my knowledge level. I could write this all out first principals. Canโ€™t find apollo server on esm.sh. Itโ€™s only on npm ๐Ÿ˜ž . Back to hanging out for this feature. esm.sh ๐Ÿ’” but still Deno โค๏ธ Just a little challenging. The compile feature is awesome to ship code in a docker container.

@cb-fred I was a hanging out for this feature until trying out esm.sh for the imports and was glad to see that it compiles. The compile feature being very useful for a project Iโ€™m doing. Deno โค๏ธ

Hope this issue will be resolved