Open stevezhu opened 1 month ago
From my testing, this seems to be a bug only when using pnpm, does that seem right to you?
it's almost like it's not following the symlinks correctly or something like that.
From my testing, this seems to be a bug only when using pnpm, does that seem right to you?
It doesn't seem to be a pnpm issue for me. I just tested with npm and got the same results.
It shouldn't be a symlink issue because this is happening within the dependency and it only happens when the index.js
for a directory import isn't explicitly defined. If you go into the dependency and manually add index.js
, the error goes away.
- Can't resolve directory imports like below. If index.js is added explicitly, then it works.
Jumping in here to +1 this problem in particular. In my Cloudflare Worker project (using npm
) the ES2015 build of @peculiar/asn1-schema has a build/es2015/errors/index.js file...
...but unfortunately the import paths within @peculiar/asn1-schema/build/es2015/ that only specify "./errors"
, without a reference to index.js, error out with No such module
:
FAIL test/index.spec.ts [ test/index.spec.ts ]
Error: No such module "<snip>/node_modules/@peculiar/asn1-schema/build/es2015/errors".
imported from "<snip>/node_modules/@peculiar/asn1-schema/build/es2015/index.js"
For sake of curiosity I found out I can go into node_modules/ and manually change these import paths to "./errors/index"
to see the error go away. This isn't a fix, of course, but does support @stevezhu's observations above.
@stevezhu @davidbarratt Try updating to the latest @cloudflare/vitest-pool-workers@0.4.21, which includes https://github.com/cloudflare/workers-sdk/pull/6455 a.k.a. "fix: ensure that directory imports in commonjs modules get resolved to their index file"
My index.js-related problem above has been fixed 🎉
@stevezhu @davidbarratt Try updating to the latest @cloudflare/vitest-pool-workers@0.4.21, which includes #6455 a.k.a. "fix: ensure that directory imports in commonjs modules get resolved to their index file"
My index.js-related problem above has been fixed 🎉
Thanks! That does fix the index.js
issue but it seems like the json resolution issue is still there.
@MasterKale I have done that, but still facing the same error: https://github.com/cloudflare/workers-sdk/issues/5367#issuecomment-2322738803
Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
What version(s) of the tool(s) are you using?
3.65.0 [Wrangler], 1.20240614.0 [workerd], 0.4.12 [@cloudflare/vitest-pool-workers]
What version of Node are you using?
22.5.0
What operating system and version are you using?
Windows 11 (I also tested on MacOS, but not too thoroughly. Fairly certain this also happens there.)
Describe the Bug
Observed behavior
It seems there are issues with module resolution for dependencies with workerd.
The two issues I've seen are:
Can't resolve directory imports like below. IfUpdate: Seems to be fixed by https://github.com/cloudflare/workers-sdk/pull/6455index.js
is added explicitly, then it works. Error logs below under "Issue 1".Expected behavior
Should be able to resolve both of these imports.
Steps to reproduce
Reproduction for issue 1: https://github.com/stevezhu/cloudflare-vitest-integration-resolution-bug Reproduction for issue 2: https://github.com/stevezhu/cloudflare-vitest-integration-resolution-bug/tree/json-resolution-error
Steps to run
pnpm i
pnpm run test
Please provide a link to a minimal reproduction
https://github.com/stevezhu/cloudflare-vitest-integration-resolution-bug
Please provide any relevant error logs
Issue 1:
Issue 2: