Skip to content
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

Deno is not able to resolve npm workspace dependency types #26306

Open
viktormarinho opened this issue Oct 16, 2024 · 4 comments
Open

Deno is not able to resolve npm workspace dependency types #26306

viktormarinho opened this issue Oct 16, 2024 · 4 comments
Assignees
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler workspaces

Comments

@viktormarinho
Copy link
Contributor

Version: Deno 2.0.0

tldr: Deno seems to be having problems resolving npm workspace dependency types with packages having only package.json; Maybe because the exports uses *?

My current structure is:

project/apps/project -> Remix app with a package.json. Runtime runs vite w/ deno, and the imports are resolved just fine. Points to project/packages/ui via "@project/ui": "^1.0.0" in package.json.

project/packages/ui -> React library exporting some components. Includes a package.json, but i've noticed that adding a deno.json kind of solves the type resolving (i'd have a package.json AND a deno.json just to be able to use deno check etc.; i've already done this for another package).

But also ends up introducing another problem: exports using a wildcard (*) seems to make all exports in deno.json stop being detected. I've tested in different packages here, and everything works until you have any export using a wildcard. In project/packages/ui/package.json, i have an exports map like that:

  "exports": {
    "./globals.css": "./globals.css",
    "./postcss.config.mjs": "./postcss.config.mjs",
    "./tailwind.config.ts": "./tailwind.config.ts",
    "./lib/*": "./src/lib/*",
    "./hooks/*": "./src/hooks/*",
    "./components/*": "./src/components/*"
  }

This does not work in deno.json, so i have to either put an export for all files, or create a barrel file, that i'd really prefer not to.

Output of deno check . at root:

error: Failed resolving types. [ERR_TYPES_NOT_FOUND] Could not find types for 'file:///Users/viktor/repos/project/packages/ui/src/components/button.tsx' imported from 'file:///Users/viktor/repos/project/apps/project/app/components/Chat.tsx'
    at file:///Users/viktor/repos/project/apps/project/app/components/Chat.tsx:6:24

Hovering the import, the Deno LSP shows me:

Resolved Dependency

Code: file​:///Users/viktor/repos/project/packages/ui/src/components/button.tsx

Types: [errored]
@viktormarinho
Copy link
Contributor Author

i have both deno.json and package.json at the root of the project:

My root deno.json:

{
  "compilerOptions": {
    "lib": [
      "deno.window",
      "dom",
      "esnext"
    ],
    "jsx": "react-jsx",
    "jsxImportSource": "react"
  },
  "fmt": {
    "exclude": [
      "*.yaml",
      "deploy/**"
    ]
  },
  "unstable": ["kv"],
  "exclude": [
    "node_modules",
    "README.md",
    "apps/**/build",
    "docs/**",
    ".github"
  ],
  "hooks": {
    "pre-commit": "deno fmt --check && deno lint"
  },
  "workspace": [
    "./apps/project",
    "./packages/ui",
    "./packages/collab"
  ]
}

My root package.json:

{
  "name": "project",
  "private": true,
  "scripts": {
    "build": "PWD=$PWD/apps/project remix vite:build",
    "dev": "PWD=$PWD/apps/project remix vite:dev",
    "lint": "deno lint . --fix",
    "fmt": "deno fmt .",
    "ui": "PWD=$PWD/packages/ui deno npm:shadcn@latest --"
  },
  "optionalDependencies": {
    "@rollup/rollup-linux-arm64-musl": "^4.22.5",
    "@rollup/rollup-linux-x64-gnu": "4.22.4"
  },
  "workspaces": [
    "./apps/*",
    "./packages/*"
  ]
}

@viktormarinho
Copy link
Contributor Author

May be related to #26305 , since import type also doesn't work for workspace dependencies... since types cannot be resolved

@jgoux
Copy link

jgoux commented Oct 16, 2024

I think it's related to my issue here: https://discord.com/channels/684898665143206084/1296203871827398696

I'm trying out Deno 2 in a full npm monorepo (so only package.json files), and the types resolution for the check command doesn't seem the read the package.json's exports key.

However the VS Code LSP is working fine. 🤔

@dsherret dsherret self-assigned this Oct 17, 2024
@dsherret dsherret added bug Something isn't working correctly workspaces labels Oct 17, 2024
@raaymax
Copy link

raaymax commented Oct 20, 2024

Same here:

error: Failed resolving types. [ERR_TYPES_NOT_FOUND] Could not find types for 'file:///Users/raay/Chat/node_modules/.deno/[email protected]/node_modules/web-push/index.js' imported from 'file:///Users/raay/Chat/deno/config/main.ts'
    at file:///Users/raay/Chat/deno/config/main.ts:1:21

Interesting part is that web-push have in it's package.json "main": "src/index.js" and deno check is trying to resolve index.js from root of the package and such file not exists.

deno lsp is working fine.

I also have package.json and deno.json in the root of my project.

@lucacasonato lucacasonato added the tsc related to the TypeScript tsc compiler label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler workspaces
Projects
None yet
Development

No branches or pull requests

5 participants