Skip to content

question: confusion about adding developer/dev dependencies #26865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
uncomfyhalomacro opened this issue Nov 14, 2024 · 21 comments
Open

question: confusion about adding developer/dev dependencies #26865

uncomfyhalomacro opened this issue Nov 14, 2024 · 21 comments
Assignees
Labels
devdependencies install triage required 👀 Deno team needs to make a decision if this change is desired

Comments

@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Nov 14, 2024

I am not quite sure how Deno knows if the dependencies I am adding is a dev dependency or not. Here is a reproduction.

deno init dev-dependency-test
cd dev-dependency-test
deno add --dev jsr:@denosaurs/argontwo

But there is no actual separation of which is a dev dependency in deno.json.

{
  "tasks": {
    "dev": "deno run --watch main.ts"
  },
  "imports": {
    "@denosaurs/argontwo": "jsr:@denosaurs/argontwo@^0.2.0",
    "@std/assert": "jsr:@std/assert@1"
  }
}

And in deno.lock.

{
  "version": "4",
  "specifiers": {
    "jsr:@denosaurs/[email protected]": "0.2.0",
    "jsr:@denosaurs/[email protected]": "0.1.4",
    "jsr:@std/assert@1": "1.0.8",
    "jsr:@std/[email protected]": "0.221.0",
    "jsr:@std/internal@^1.0.5": "1.0.5"
  },
  "jsr": {
    "@denosaurs/[email protected]": {
      "integrity": "1ce2f4c90ba3643e6fffd0d9be059f7cacfb62cf1b314049b6c7c71d87cb92a1",
      "dependencies": [
        "jsr:@denosaurs/lz4",
        "jsr:@std/encoding"
      ]
    },
    "@denosaurs/[email protected]": {
      "integrity": "ad5d556c02eb01fe1e0f2e953d7be066a14870afe149b1aed1ced019460f6aa1"
    },
    "@std/[email protected]": {
      "integrity": "ebe0bd7eb488ee39686f77003992f389a06c3da1bbd8022184804852b2fa641b",
      "dependencies": [
        "jsr:@std/internal"
      ]
    },
    "@std/[email protected]": {
      "integrity": "d1dd76ef0dc5d14088411e6dc1dede53bf8308c95d1537df1214c97137208e45"
    },
    "@std/[email protected]": {
      "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba"
    }
  },
  "workspace": {
    "dependencies": [
      "jsr:@denosaurs/[email protected]",
      "jsr:@std/assert@1"
    ]
  }
}

In Node, there is a field called devDependencies which makes it easy to track which dependency is a dev dependency or not. Maybe this --dev flag was supposed to declare a package as a dev dependency in deno.lock. Was this overlooked or something that is still being worked on?

@devjume
Copy link

devjume commented Nov 16, 2024

I looked into the Deno source code, and it seems that the --dev flag currently only works with the package.json file when using the npm: prefix. This is help text from source code for the --dev flag: "Add the package as a dev dependency. Note: This only applies when adding to a package.json file." Source

In my opinion, it would be beneficial if the --dev flag could also add a separate section for dev dependencies in the deno.json file. This would improve dependency management, similar to how devDependencies are handled in Node.js with package.json

Currently, there is no way to manage dev dependencies for packages installed using the jsr: prefix. The --dev flag only works when using the npm: prefix and requires a package.json file in the project. It would be great if we could have a consistent way to handle dev dependencies across different types of package installations.

Edit: There was note about the --dev flag in Deno 2.0 Release Candidate blog post

@uncomfyhalomacro
Copy link
Contributor Author

I looked into the Deno source code, and it seems that the --dev flag currently only works with the package.json file when using the npm: prefix. This is help text from source code for the --dev flag: "Add the package as a dev dependency. Note: This only applies when adding to a package.json file." Source

In my opinion, it would be beneficial if the --dev flag could also add a separate section for dev dependencies in the deno.json file. This would improve dependency management, similar to how devDependencies are handled in Node.js with package.json

Currently, there is no way to manage dev dependencies for packages installed using the jsr: prefix. The --dev flag only works when using the npm: prefix and requires a package.json file in the project. It would be great if we could have a consistent way to handle dev dependencies across different types of package installations.

Edit: There was note about the --dev flag in Deno 2.0 Release Candidate blog post

Hey. Thanks for the response! That's a lot of good info!

@krutoo
Copy link

krutoo commented Dec 5, 2024

@uncomfyhalomacro @devjume is there any plan to add dev dependencies to deno.json?

@BlackAsLight
Copy link

As it stands, Deno doesn't have a need to separate the dependencies. If you're publishing to JSR, the only dependencies listed are the ones actually used in the code. If you fork a Deno repo and want to install all its dependencies listed in deno.json then you can do deno install but if you only want to install the dependencies required to run the code then you can do deno install --entrypoint <main.ts>

@tribals

This comment was marked as off-topic.

@tribals

This comment was marked as off-topic.

@bartlomieju bartlomieju added install triage required 👀 Deno team needs to make a decision if this change is desired labels Dec 6, 2024
@BlackAsLight

This comment was marked as off-topic.

@tribals

This comment was marked as off-topic.

@tribals

This comment was marked as off-topic.

@dsherret
Copy link
Member

dsherret commented Dec 6, 2024

Let's please stay on topic here instead of going into a side rant.

As @BlackAsLight mentioned, in Deno dependencies for production are figured out based on what your code uses. For example, if you have an entrypoint of main.ts then Deno will analyze that and figure out the dependencies based on what that module graph uses. That still has some improvements to make for npm packages and just general usability and documentation. For example, Deno doesn't figure out the subset of npm packages to include for production. @nathanwhit has been actively working on improving this and we'll have something for Deno 2.2 (I'll try to follow up here with the issue... I can't find it at the moment).

Personally, I think Deno should have a way of representing dev dependencies in the deno.json. This would have several benefits:

  1. It's something developers are familiar with from npm.
  2. Deno can error when a dev depenendency is used in production code (ex. you're publishing a package to JSR and accidentally have an import to a dev dependency).
  3. It can be a way to easily include npm phantom deps in production or optional peer dependencies without having to import the package in the production code in order to include it.

That said, some people are extremely against this on the team, so it might be a hard sell.

@krutoo
Copy link

krutoo commented Dec 6, 2024

@dsherret agree, I think in Deno we should have a way to declarative define dependencies that need only during work exactly with source code of package - aka dev dependencies

It would also be really cool to have some kind of built-in analyzer of problems with declaring dependencies and dev dependencies

For example, so that some CLI tool would tell me that I specified a dependency as dev but it is actually used in the code that will be packaged

@tribals

This comment was marked as off-topic.

@dsherret

This comment was marked as off-topic.

@DrSensor
Copy link

DrSensor commented Dec 9, 2024

rather than devDependencies, i would suggest something more granular

{
  "tasks": {
    "build": {
      "command": "rollup -c",
      "imports": {
        "rollup": "npm:rollup@4",
        "@unplugin/isolated-declarations": "jsr:@unplugin/isolated-decl@latest",
        "@rollup/iife": "npm:rollup-plugin-iife@latest"
      },
    },
    "test": {
      "command": "playwright test",
      "dependencies": ["build"],
      "nodeModulesDir": "manual",
      "imports": {
        "playwright": "npm:playwright@1",
        "@playwright/test": "npm:@playwright/test@1"
      }
    }
  }
}

for adding dependencies via cli

deno add npm:rollup --task build,bundle

@krutoo
Copy link

krutoo commented Dec 10, 2024

Also I don't clearly understand how dependencies will work for deno.json

For example in my library I have react from https://esm.sh:

{
  "imports": {
    "react": "https://esm.sh/[email protected]"
  }
}

I want to use my library in other project

In this project i have react from NPM:

{
  "imports": {
    "react": "npm:[email protected]"
  }
}

How can I define react in my library for avoid install 2 copies of react from 2 sources?

@BlackAsLight
Copy link

Also I don't clearly understand how dependencies will work for deno.json

For example in my library I have react from https://esm.sh:

{
  "imports": {
    "react": "https://esm.sh/[email protected]"
  }
}

I want to use my library in other project

In this project i have react from NPM:

{
  "imports": {
    "react": "npm:[email protected]"
  }
}

How can I define react in my library for avoid install 2 copies of react from 2 sources?

Why can't your library import npm:react and still be used in other projects?

@krutoo
Copy link

krutoo commented Dec 10, 2024

Why can't your library import npm:react and still be used in other projects?

@BlackAsLight Honestly, this is because I don't know how to add types to NPM-version of React

I tried to find guides about how to properly add @types/react to Deno with deno.json but there is no such guides

I asked here:
denoland/react-vite-ts-template#1

And here:
MoonHighway/deno-2-course#4

And here:
#27257

But there is no asnwer at this time

That's why I was going to replace react from npm to react from esm.sh

@dandv
Copy link
Contributor

dandv commented Jan 14, 2025

I was also confused by deno add --dev. In the meantime, can the docs be updated for https://docs.deno.com/runtime/reference/cli/add/#options-dev to say a bit more than "Add as a dev dependency."?

@hongkongkiwi
Copy link

hongkongkiwi commented Mar 19, 2025

Why can't your library import npm:react and still be used in other projects?

@BlackAsLight Honestly, this is because I don't know how to add types to NPM-version of React

I tried to find guides about how to properly add @types/react to Deno with deno.json but there is no such guides

I asked here: denoland/react-vite-ts-template#1

And here: MoonHighway/deno-2-course#4

And here: #27257

But there is no asnwer at this time

That's why I was going to replace react from npm to react from esm.sh

On this topic it's easy to do this in deno.json e.g.:

{
  "compilerOptions": {
    "types": [
      "npm:@aws-sdk/types@^3.692.0"
    ]
  }
}

However that's not really related to the OPs question about adding dev dependencies. I too found the documentation very lacking on this point when coming from node_modules.

@bartlomieju bartlomieju self-assigned this Apr 29, 2025
@kingbri1
Copy link

kingbri1 commented May 16, 2025

Agreed on this. I am currently using deno compile and love the tooling, but the compile includes typing dependencies (such as the @types family), which shouldn't be needed to run the final bin.

For example, @types/node isn't necessary in prod, but inflates the build size by 2 MB.

I'd be happy to make this a separate issue since it deals with Deno compile.

@dsherret
Copy link
Member

@kingbri1 see #19764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devdependencies install triage required 👀 Deno team needs to make a decision if this change is desired
Projects
None yet
Development

No branches or pull requests