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

deno compile cannot resolve npm modules #16632

Closed
cb-fred opened this issue Nov 14, 2022 · 18 comments · Fixed by #19005
Closed

deno compile cannot resolve npm modules #16632

cb-fred opened this issue Nov 14, 2022 · 18 comments · Fixed by #19005
Assignees

Comments

@cb-fred
Copy link

cb-fred commented Nov 14, 2022

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

Given the following script:

// main.ts
import express from "npm:[email protected]";
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 '[email protected]'
    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

@bartlomieju
Copy link
Member

As per #15960 it's not yet supported

@cb-fred
Copy link
Author

cb-fred commented Nov 14, 2022

Ah, indeed, seems I overlooked that part in the release notes 😅

In any case, congrats and thanks for this release 👍

@dsherret
Copy link
Member

It was a bug that it didn't give you a nice error message explaining this. That will be fixed in #16637.

@NetOpWibby
Copy link

NetOpWibby commented Nov 18, 2022

Hijacking this because while I'm not having issues compiling, my app doesn't run.

deno compile --allow-env --allow-net --allow-read --unstable main.ts

# output
Check file:///~/main.ts
Compile file:///~/main.ts
Emit pastry-server

And then

./pastry-server

# output
error: Module not found

The error message is not helpful, so I searched the Deno Discord, which led me to this issue. I do have an npm module in my project.

import * as packet from "npm:[email protected]";

Guess I'll just keep an eye on this issue and pause that aspect of my project for now.

EDIT: I actually fixed my issue. Turns out, import_map.json doesn't work with compiled apps. At least not with designing your own shortcuts aside from "/": "./" and "./": "./".

@royalknight56
Copy link

Hope this issue will be resolved

@chrisbrocklesby
Copy link

+1 for npm support in Deno compile.

@dingiyan
Copy link

+1 I'm looking forward to this feature.

@sshwy
Copy link

sshwy commented Jan 19, 2023

+1 looking forward to this feature.

@bartlomieju
Copy link
Member

@dsherret is working on this feature.

@lino-levan
Copy link
Contributor

@bartlomieju considering deno compile is now (or soon to be?) deprecated, should this issue remain open?

@dsherret
Copy link
Member

dsherret commented Mar 1, 2023

@lino-levan no, deno compile is not going anywhere. I think you’re thinking of deno bundle.

@lino-levan
Copy link
Contributor

Ah, sorry I misread this issue 😅

@johnstonmatt
Copy link

this one is important for my team working on polyseam/cndi, thanks for looking into this!

@dsherret
Copy link
Member

dsherret commented Apr 5, 2023

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

@Hillsie
Copy link

Hillsie commented Apr 13, 2023

@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 ❤️

@Hillsie
Copy link

Hillsie commented Apr 14, 2023

Okay, need to eat my hat. Want to get @apollo/[email protected] 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.

@Creative-Difficulty
Copy link

@Hillsie same

@nabil-mansouri
Copy link

+1 looking for this feature! thank you very much guys

dsherret added a commit that referenced this issue May 11, 2023
This is the initial support for npm and node specifiers in `deno
compile`. The npm packages are included in the binary and read from it via
a virtual file system. This also supports the `--node-modules-dir` flag,
dependencies specified in a package.json, and npm binary commands (ex.
`deno compile --unstable npm:cowsay`)

Closes #16632
dsherret added a commit that referenced this issue May 11, 2023
This is the initial support for npm and node specifiers in `deno
compile`. The npm packages are included in the binary and read from it via
a virtual file system. This also supports the `--node-modules-dir` flag,
dependencies specified in a package.json, and npm binary commands (ex.
`deno compile --unstable npm:cowsay`)

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

Successfully merging a pull request may close this issue.