deno
deno copied to clipboard
Deno is not able to resolve npm workspace dependency types
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]
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/*"
]
}
May be related to #26305 , since import type also doesn't work for workspace dependencies... since types cannot be resolved
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. 🤔
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.
Same issue here. It works fine to run code like deno run however it makes deno test failed due to
ERR_TYPES_NOT_FOUND. Any workaround ?
The workaround atm is to use --no-check with deno test
The workaround atm is to use
--no-checkwithdeno test
What i wanted was to run deno check, so this would not make sense for me.
My current workaround is using a deno.json file listing all exports, just for type checking, besides the package.json file.
I had a "main": "index.ts" in my package.json, and fixed the issue by also having a "types": "index.ts" in my package.json