admin管理员组文章数量:1026087
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/
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-
"…install a dev-only dependency": Can you edit the question to clarify what is meant by "install"? Are you referring to the specific scenario of using npm dependencies while using
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:18 -
@jsejcksn Edited. I'm just finding a thing in Deno like
devDependencies
in Node.js/npm – typed-sigterm Commented Nov 20, 2024 at 12:38 -
1
Looks like there is no option to add a package as a dev dependency for packages published on JSR. The
--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
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/
本文标签: javascriptHow to add devonly dependencies in DenoStack Overflow
版权声明:本文标题:javascript - How to add dev-only dependencies in Deno? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745635760a2160437.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