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

Vitest bug: "Error: ENOENT: no such file or directory" #763

Closed
amorey opened this issue Apr 14, 2024 · 2 comments
Closed

Vitest bug: "Error: ENOENT: no such file or directory" #763

amorey opened this issue Apr 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@amorey
Copy link

amorey commented Apr 14, 2024

When I run vitest with the miniflare environment I get a missing file error due to one of the build files not being present. Here's a minimal vite project that reproduces the error:
https://github.com/amorey/miniflare-vitest-bug

git clone [email protected]:amorey/miniflare-vitest-bug.git
cd miniflare-vitest-bug
pnpm install
pnpm test

In this particular example, the error is that the build artifact dist/main.cjs is missing. If I remove the "main" definition from package.json, the error goes away.

@RamIdeas RamIdeas added the bug Something isn't working label Apr 15, 2024
@penalosa
Copy link
Contributor

It looks like your project's package.json file points to dist/main.cjs, but that file doesn't exist. Did you generate the project from a template? It might be that you need to run the build script first (pnpm run build in your case).

In Miniflare v3 we've added a new way to run unit tests against your Workers using the actual Workers runtime (workerd), and that's what we recommend for projects going forward. You can try it out at https://developers.cloudflare.com/workers/testing/vitest-integration/

@amorey
Copy link
Author

amorey commented Jul 22, 2024

It looks like your project's package.json file points to dist/main.cjs, but that file doesn't exist. Did you generate the project from a template? It might be that you need to run the build script first (pnpm run build in your case).

The tests don't depend on the build files and running the tests in a node environment doesn't throw an error so why would running them in a miniflare environment throw an error?

In Miniflare v3 we've added a new way to run unit tests against your Workers using the actual Workers runtime (workerd), and that's what we recommend for projects going forward. You can try it out at https://developers.cloudflare.com/workers/testing/vitest-integration/

I migrated the example to Miniflare v3 and the original error went away but now I can't see how to integrate Miniflare v3 into the main project (https://github.com/kubetail-org/edge-csrf). In the main project, I'm testing the code in different environments by switching the vitest environment flag. For example, here's the test-all script definition in package.json:

"test-all": "vitest run --environment node && vitest run --environment edge-runtime && vitest run --environment miniflare"

However, miniflare v3 doesn't use the environment flag anymore. How can I implement the same behavior in v3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants