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.
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.
Share Improve this question edited Nov 20, 2024 at 12:34 typed-sigterm asked Nov 17, 2024 at 12:19 typed-sigtermtyped-sigterm 1,24711 silver badges35 bronze badges 3 |1 Answer
Reset to default 4See 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 innode_modules
when some code tries to access it.With Deno-style though, there is no
node_modules
; nevertheless, dependencies will also be cached automatically at runtime. You can (and should, especially in production) rundeno cache
ahead of time, of course - so you can prepopulate the cache with all identified packages, before they are used. 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 really required. According to Deno's docs, imports in the code should be "unequivocal": e.g. they must specify the package registry or source - with thenpm:
,node:
orjsr:
prefixes, for example. And this "extra" info is enough for Deno's runtime to repopulate its cache on demand.
References:
- https://medium/deno-the-complete-reference/dependency-installation-in-deno-41caf01ec903
- https://docs.deno/examples/node_built_in/
- https://docs.deno/runtime/fundamentals/node/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745635761a4637382.html
package.json
and a localnode_modules
directory? By default, Deno downloads imported module data into an immutable, global cache. Read more at the docs: Modules and dependencies – jsejcksn Commented Nov 19, 2024 at 23:18devDependencies
in Node.js/npm – typed-sigterm Commented Nov 20, 2024 at 12:38--dev
flag works only for packages published on npm and requirespackage.json
file. Find out more information in the reply of the GitHub issue you have linked: github/denoland/deno/issues/26865#issuecomment-2480833535 – Kotkoroid Commented Nov 21, 2024 at 16:58