ventgrey
ventgreyโ€ข2mo ago

2.0 node_modules directory approach breaks when using private npm packages.

For some reason Deno 1.0 wasn't able to directly install private npm packages when using deno add. An alternative solution using .npmrc configuration files and enabling nodeModulesDir inside deno.json made it simpler as you would only need to deno cache <entrypoint.ts> to download your private npm package to the projects node_modules directory. If such package is not present at that time inside the directory the deno compile command would fail when building container images. This is why node_modules/ is needed. However, Deno 2.0 changed this and now, no matter what approach you take, you end up with a container constantly erroring out saying: error: Unable to load /tmp/deno-compile-example_app/app/node_modules/.deno/@my-org+mylib@1.0.0/node_modules/@my-org/mylib/index.js imported from file:///tmp/deno-compile-example_app/app/src/app.ts. Is there a way to force things to work using a deno.json file? I see that the option can now be set to manual, but why on earth would I want to go back to a package.json file? Should I just manually copy cache directories at build time inside the image to trick deno into symlinking them into the node_modules directory?
7 Replies
ventgrey
ventgreyOPโ€ข2mo ago
Fixed by keeping deps inside a minimal package.json file and the important stull like import maps inside deno.json it's kind of carcinogenic but it does the job ๐Ÿ‘ Update: Apparently bcrypt might not be compatible with deno 2.0 as the deno compile binary doesn't find the library if it's being used as a library dependency.
bartlomieju
bartlomiejuโ€ข2mo ago
@ventgrey sorry for the trouble, could you open a GitHub issue for this?
ventgrey
ventgreyOPโ€ข2mo ago
Is it too late for this? Any extra context that I need to add in such issue? ๐Ÿค”
bartlomieju
bartlomiejuโ€ข2mo ago
Not really, it would still be useful to have an issue I think the context you put here is enough ๐Ÿ‘
ventgrey
ventgreyOPโ€ข2mo ago
Okay, I'll open one ๐Ÿ™‚ I've got even more context. It seems that the underlying issue is with libraries that depend on npm packages that need external FFI mods, this results in the deno compile command running correctly but not inserting the main ESM script in the final binary
bartlomieju
bartlomiejuโ€ข2mo ago
Okay, great that you got more info! :deno_thankyou:
ventgrey
ventgreyOPโ€ข2mo ago
I think there is already an issue that I can link to this. I've started redacting my issue though, https://github.com/denoland/deno/issues/23266
GitHub
Add support for node native addons / FFI in deno compile ยท Issue ...
Discussed in #23255 Originally posted by babakfp April 6, 2024 Hi ๐Ÿ‘‹ parcel-bundler/lightningcss#712 Based on this comment parcel-bundler/lightningcss#712 (comment) and this: (I used this library ht...