Reputation: 1067
In Node.js, we can use npm install -D foo
to add a dependency into package.json > devDependencies
. When the package is published and used as a dependency, devDependencies
won't be installed.
But in deno.json
, there is only imports
, no devImports
. According to Deno v2 RC announcement, we can use deno add --dev
. But this only add contents to deno.lock
, not adding anything to deno.json
. I tried deno add --dev eslint
(not migrating Deno Lint yet), but it complained eslint: command not found
.
When package.json
exists, it's added to package.json
, but I'm trying finding a pure-Deno solution.
I found denoland/deno#26865, but no answers are there.
Upvotes: 4
Views: 676
Reputation: 11973
See this answer by "crowKats" here, but in short:
With a “npm-style” Deno project, based on package.json
, use
deno add --dev
for dev dependencies, ordeno add
for production dependencies.But with a deno.json or deno.jsonc project, use
deno add
, in either case.There’s no need to segregate development and production dependencies for Deno 2+ native projects. Deno is smart: it only caches and installs the dependencies needed for the current runtime.
While I’m not a Deno expert myself (still learning), my suggestion is that you need to read Deno's documentation attentively but also with an "open mind" (don't expect it to just be a cuter, giant-lizard version of npm
):
In the npm world, npm install
is required before running any project, otherwise the application will break: dependencies wont't be available in node_modules
when some code tries to access it.
With Deno-style though, there is no node_modules
, and dependencies might also be cached automatically at runtime. You can (and should, especially in production) run deno cache
ahead of time, of course. But if you, say, add a new dependency or make a hotfix change in production, Deno's expected behaviour is to detect it, automatically download the dependency to its cache, and continue executing the application without further interruption.
To make things even weirder, this also means not even deno add
is totally required. According to Deno's docs, imports in the code should be "unequivocal": e.g. they must specify the package registry or source - with the npm:
, node:
or jsr:
prefixes, for example. And this "extra" info is enough for Deno's runtime to repopulate its cache, if needed.
References:
Upvotes: 1