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

Unable to import between deno workspace members #27938

Open
nagyatka opened this issue Feb 2, 2025 · 3 comments
Open

Unable to import between deno workspace members #27938

nagyatka opened this issue Feb 2, 2025 · 3 comments
Labels
needs investigation requires further investigation before determining if it is an issue or not workspaces

Comments

@nagyatka
Copy link

nagyatka commented Feb 2, 2025

Version: Deno 2.1.9

First of all, I really appreciate the effort you put in Deno! I think it is an awesome project, and I hope you will have a lot of success with it.

I'm planning to move/migrate my next project from node to Deno, so I have started to recreate my original project setup. Unfortunately, I ran into a problem with importing between Deno workspace members:
I have two member projects common and db. Project common contains utility function and types that I share between other member projects, for example generating a nanoid().
When I try to import nanoid(), from the common project, everything seems fine in the VSCode, the Deno LSP easily finds the references, but when I try to execute any commands it fails with a module not found error.

I created a git repo to easily reproduce the bug: https://github.com/nagyatka/deno-drizzle-workspace-issue

deno i
deno task db:migrate

output:

anagy@machine-ruogfh34 deno-drizzle-workspace-issue % deno task db:migrate
Task db:migrate cd packages/db && deno task --node-modules-dir migrate
Task migrate deno -A --node-modules-dir npm:drizzle-kit generate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/projects/deno/deno-drizzle-workspace-issue/packages/db/drizzle.config.ts'
Error: Cannot find module '@my-project/common'
Require stack:
- /projects/deno/deno-drizzle-workspace-issue/packages/db/src/utils.ts
- /projects/deno/deno-drizzle-workspace-issue/packages/db/src/schema.ts
- /projects/deno/deno-drizzle-workspace-issue/node_modules/.deno/[email protected]/node_modules/drizzle-kit/bin.cjs
    at Function.Module._resolveFilename (node:module:617:15)
    at Function.Module._load (node:module:495:27)
    at Module.require (node:module:679:19)
    at require (node:module:810:16)
    at Object.<anonymous> (file:///projects/deno/deno-drizzle-workspace-issue/packages/db/src/utils.ts:25:21)
    at Object.<anonymous> (file:///projects/deno/deno-drizzle-workspace-issue/packages/db/src/utils.ts:34:4)
    at Module._compile (node:module:743:34)
    at Module._compile (file:///projects/deno/deno-drizzle-workspace-issue/node_modules/.deno/[email protected]/node_modules/drizzle-kit/bin.cjs:13802:30)
    at loadMaybeCjs (node:module:768:10)
    at Module._extensions..js (node:module:753:12) {
  code: "MODULE_NOT_FOUND",
  requireStack: [
    "/projects/deno/deno-drizzle-workspace-issue/packages/db/src/utils.ts",
    "/projects/deno/deno-drizzle-workspace-issue/packages/db/src/schema.ts",
    "/projects/deno/deno-drizzle-workspace-issue/node_modules/.deno/[email protected]/node_modules/drizzle-kit/bin.cjs"
  ]
}
@dsherret dsherret added the needs investigation requires further investigation before determining if it is an issue or not label Feb 3, 2025
@dsherret
Copy link
Member

dsherret commented Feb 3, 2025

Not sure what's going on here, but it looks like something is doing cjs resolution and require doesn't support Deno workspaces. Marking this as needs investigation for now. For compatibility and as a workaround, you might need to add package.json workspace at the root with a package.json in the packages/common folder so that it does node resolution between the projects for the time being, but I don't understand why it's not doing regular resolution here.

@nagyatka
Copy link
Author

nagyatka commented Feb 3, 2025

Thanks for the quick reply and the suggestion. I'll try it, hopefully it will temporarily solve the problem. if I can help you with the investigation let me know.

@nagyatka
Copy link
Author

nagyatka commented Feb 4, 2025

I found another error that maybe related to this one. Since, I'm not sure it is a vite plugin issue or workspace issue i have created it in the plugin's repo denoland/deno-vite-plugin#41 , but maybe these errors are related to each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation requires further investigation before determining if it is an issue or not workspaces
Projects
None yet
Development

No branches or pull requests

3 participants