This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Vite unable to resolve a dependency that node solves, even when index is added to the path #14769
Labels
You can continue the conversation there. Go to discussion →
Describe the bug
I checked this error on the web and specifically for vite, and although it seems like a common discussion, I don't understand why it doesn't work on my case:
I published the lib user-credits on npm and while it resolves in regular node apps it cannot be resolved through my svelte app.
Now when I launch the app (vite dev), I get:
So I went to my package.json and I pointed it to the directory unpacked from npm like follows:
"dependencies": {
"@sveltejs/adapter-node": "1.3.1",
"@tsconfig/svelte": "^5.0.2",
"preline": "^1.9.0",
"user-credits": "link:..\user-credits-ui\node_modules\.pnpm\user-credits@0.9.7-alpha\node_modules\user-credits"
}
Surprise! Everything works fine!
Can someone explain me how I am supposed to export the lib please?
Even when I explicitely added index to the folder imports, it still didn't resolve:
Cannot find module 'C:\Users\zhamd\work\user-credits-ui\node_modules.pnpm\user-credits@0.9.8-alpha\node_modules\user-credits\dist\db\dao\index' imported from C:\Users\zhamd\work\user-credits-ui\node_modules.pnpm\user-credits@0.9.8-alpha\node_modules\user-credits\dist\index.js
** Is it searching for an index.js or index.ts file? Because there's an index.js and and index.d.ts file at C:\Users\zhamd\work\user-credits-ui\node_modules.pnpm\user-credits@0.9.8-alpha\node_modules\user-credits\dist\db\dao\ **
NOTE: here's the problematic npm project's github and this is the client's one
In the file below, I tested that the same import works fine in a regular node app that i launch with node fileName.js
TestUserCredits.zip
Reproduction
https://stackblitz.com/edit/vitejs-vite-6sixhn?file=main.js
Steps to reproduce
I wasn't able to see the logs on stackblitz, but commenting the two lines below in main.js shows the vite page, uncommenting the import will immediately show a blank page
So just call
details:
I added the dependencies
Modified counter.js
And implemented an interface from user-credits:
the import will fail to find node_modules\user-credits\dist\db\dao
System Info
Used Package Manager
pnpm
Logs
Failed to load dependency
``` vite:import-analysis 6.60ms [5 imports rewritten] src\lib\example\impl\model\OfferProps.ts +6ms vite:transform 37.52ms /src/lib/example/impl/model/OfferProps.ts +7ms 5:32:06 PM [vite] Error when evaluating SSR module /src/lib/example/Resolver.ts: failed to import "user-credits" |- Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\zhamd\work\user-credits-ui\node_modules\.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\db\dao\index' imported from C:\Users\zhamd\work\user-credits-ui\node_m odules\.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\index.js at new NodeError (node:internal/errors:399:5) at finalizeResolution (node:internal/modules/esm/resolve:326:11) at moduleResolve (node:internal/modules/esm/resolve:945:10) at defaultResolve (node:internal/modules/esm/resolve:1153:11) at nextResolve (node:internal/modules/esm/loader:163:28) at ESMLoader.resolve (node:internal/modules/esm/loader:838:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) at ModuleWrap. (node:internal/modules/esm/module_job:77:40) at link (node:internal/modules/esm/module_job:76:36)5:32:06 PM [vite] Error when evaluating SSR module /src/routes/+layout.svelte: failed to import "/src/lib/example/Resolver.ts"
|- Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\zhamd\work\user-credits-ui\node_modules.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\db\dao\index' imported from C:\Users\zhamd\work\user-credits-ui\node_m
odules.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\index.js
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36)
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\zhamd\work\user-credits-ui\node_modules.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\db\dao\index' imported from C:\Users\zhamd\work\user-credits-ui\node_modu
les.pnpm\user-credits@0.9.10-alpha\node_modules\user-credits\dist\index.js
The text was updated successfully, but these errors were encountered: