deno install Omit/exclude dev dependencies from package.json
I have a sveltekit project that I want to convert to using deno 2.0 (currently using 2.1.9). I can run
deno build
(to pre render my sveltekit app) and cd build && deno index.js
works like a charm. However, I also have some api routes that use npm packages.
Everything works fine when running locally.
But when I build my Docker image, I would like to install only the needed dependencies (those under dependencies). I don’t need the devDependencies
, such as lints and types. In npm, I would use --omit=dev
(I believe Bun has a similar flag).
Is there a way to exclude devDependencies
when running deno install
I have checked the manual: https://docs.deno.com/runtime/reference/cli/install/, but I couldn't find anything about excluding deDependencies
.
The closest thing I found was this: https://docs.deno.com/runtime/reference/cli/install/#options-entrypoint, but it’s unclear which file I should specify for sveltekit.
Does anyone know if there is a way to omit devDependencies
when running deno install
or should I use --entrypoint=file1.file2
, if so which file should I select? Or is there a better way to handle this?
Or is there a better way to handle this?Deno
deno install
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
8 Replies
I have a separate deno.json with my prod dependencies, and wrote a little post build adapter in the svelte config that copies that deno.json to the output directory to work around this
Thanks for the advice, maybe that is the intention all along. But how do you handle the lock file? Do you use the same lock file?
Anyone think this is worth adding as an idea or suggestive ticket on Github? Or Im I bringing up an issue that's seldom used?
I need to test again, but originally I had issues with including the lockfile (I’m deploying to deploy) so I don’t have it atm. It’s unfortunate but at least my prod dependencies don’t include hundreds other deps lol, so it’s okay for now
I also have to be careful about which deps I use because if they use global node APIs it breaks (I’m using node adapter currently, node adapter doesn’t fix all the globals)
There’s a pretty large sveltekit issue in deno repo where even svelte and related maintainers participate, things are continuously getting better
I think since your are building a container image you won’t have the same issues I do as you have more control over flags passed to the deno runtime
Hmmmm, is it just me or....
Deno
is a runtime environment (just like Node
) that runs your code or optionally build
an executable that already eliminates stuff using tree-shaking.
- It is not a bundler
, for that you need to use external tools like esbuild
.
devDependencies
are relevant when building the final product (the executable
) from scratch, but not when bundling
just the code you wrote that makes use of those...
To make it clear: install
needs all devDependencies
to build an executable...
@Agowan Maybe you are confusing install
with add
? 🤔
- See: deno help install
and deno help add
@coty Why the 👎 , explain 🤔@coty thank you for your input are you referring to this issue: https://github.com/denoland/deno/issues/17248 ?
GitHub
Support for SvelteKit · Issue #17248 · denoland/deno
Prompted by discussion on Discord I tried to get SvelteKit working in Deno. After an hour of debugging I found the main blocker: by default SvelteKit installed Node adapter, which does a bit of set...
@©TriMoon™ thank you for your input.
Regarding my use case and the need to exclude devDependencies: I’m trying to run SvelteKit with Deno 2 (both during bundle and runtime), and since SvelteKit is a compiler rather than a runtime, its dependencies (among others) are not needed in production. Therefore, I want to exclude devDependencies for production and, of course, reduce the size of my Docker image.
I’m not confusing
install
with add
(I do not intend to add new dependencies to my package.json
). I simply want to run an install of all production npm packages (that is omit all dev dependencies) so that I can copy just the needed npm packages over during a multi-stage Docker image build.
(But as you say I use all npm packages during compiling)
Maybe you could bundle the sveltekit with an executable...So I revisited this just now and everything is so nice. Here's my deno sveltekit project https://github.com/cotyhamilton/taylor-swift-lyrics
Check that last PR for relevant changes, but yeah, using the deno.json and deno.lock are working great, how deno.lock handles the dependencies is really cool, it's using workspace feature to handle deps in both deno.json and package.json. And it looks like as long as they're the same version, for "prod" deps in deno.json, there's no duplication. Really cool! I also added a Dockerfile to test all this easily, but it is all working on deploy now!
Yeah that's the github issue I mentioned, the last thing they're waiting on is rootDirs compiler option working in the language server. After that gets fixed I'm pretty sure we can strip out the package.json and tsconfig, and do sveltekit in a deno native way (after some extra config), and use deno lsp!
This is another project to keep eye on for ideas https://github.com/trakt/trakt-lite/tree/main they have a deno monorepo with a sveltekit project in it. They've also been active in that issue
GitHub
GitHub - cotyhamilton/taylor-swift-lyrics: Taylor Swift lyrics search
Taylor Swift lyrics search. Contribute to cotyhamilton/taylor-swift-lyrics development by creating an account on GitHub.
GitHub
GitHub - trakt/trakt-lite: A mostly harmless SvelteKit application ...
A mostly harmless SvelteKit application for Trakt. May contain traces of existential dread, inappropriate humor, and an unhealthy obsession with obscure Eastern European cinema. Proceed with caut...
@coty Thank you! I will look in to it!