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
- feat(compile): unstable npm and node specifier support (#19005) This is the initial support for npm and node specifiers in `deno compile`. The npm packages are included in the binary and read from i... — committed to denoland/deno by dsherret a year ago
- feat(compile): unstable npm and node specifier support (#19005) This is the initial support for npm and node specifiers in `deno compile`. The npm packages are included in the binary and read from i... — committed to denoland/deno by dsherret a year ago
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