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

🐛 BUG: SyntaxError: Named export 'compileModuleRules' not found. error when using pnpm create cloudflare then pnpm test #5311

Closed
Xvezda opened this issue Mar 20, 2024 · 6 comments
Labels
bug Something that isn't working

Comments

@Xvezda
Copy link

Xvezda commented Mar 20, 2024

Which Cloudflare product(s) does this pertain to?

C3

What version(s) of the tool(s) are you using?

2.15.0 [C3], 3.0.0 [Wrangler]

What version of Node are you using?

21.6.2

What operating system and version are you using?

Mac Sonoma 14.3.1

Describe the Bug

Observed behavior

Unhandled error occurs when running test on repository created via C3 using pnpm

Expected behavior

Tests should run without errors, same as when the repository is created using npm create cloudflare.

Steps to reproduce

pnpm create cloudflare@latest repro-pnpm-c3-test-issue --type=hello-world --deploy=false --ts --git
cd repro-pnpm-c3-test-issue
pnpm test

Please provide a link to a minimal reproduction

https://github.com/Xvezda/repro-pnpm-c3-test-issue

Please provide any relevant error logs

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
SyntaxError: Named export 'compileModuleRules' not found. The requested module 'miniflare' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'miniflare';

 ❯ ModuleJob._instantiate node:internal/modules/esm/module_job:132:21
 ❯ ModuleJob.run node:internal/modules/esm/module_job:214:5
 ❯ ModuleLoader.import node:internal/modules/esm/loader:323:24
 ❯ ViteNodeRunner.interopedImport node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:383:28
 ❯ ViteNodeRunner.directRequest node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:253:24
 ❯ ViteNodeRunner.cachedRequest node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:189:14
 ❯ ViteNodeRunner.executeId node_modules/.pnpm/[email protected]/node_modules/vite-node/dist/client.mjs:165:12
 ❯ resolveCustomPool node_modules/.pnpm/[email protected]/node_modules/vitest/dist/vendor/cli-api.RIYLcWhB.js:4033:20
 ❯ async file:/[REDACTED]/repro-pnpm-c3-test-issue/node_modules/.pnpm/[email protected]/node_modules/vitest/dist/vendor/cli-api.RIYLcWhB.js:4083:27
@Xvezda Xvezda added the bug Something that isn't working label Mar 20, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Mar 20, 2024
@awais-codes
Copy link

bump

@mrbbot
Copy link
Contributor

mrbbot commented Mar 25, 2024

Hey! 👋 I just tried to run the above commands and the tests passed successfully. 😕 Which version of pnpm are you using?

@awais-codes
Copy link

awais-codes commented Mar 25, 2024

I am trying to add vitest to an existing monorepo project and same error occurred for me. Apparently this is originating from vitest-pool-workers package which exposes ESM and has miniflare as dependency while miniflare itself exposes CommonJS. The error is regarding named import as stated in the issue description. Strangely enough this did not happen for me when I bootstrapped my new repo using the command: npm create cloudflare@latest <repo-name> -- --type=hello-world

I am using similar versions of packages as well.

npm: 10.2.4

@mrbbot
Copy link
Contributor

mrbbot commented Mar 25, 2024

@awais-codes This error means your version of miniflare is too old. Please ensure you're using the latest versions of @cloudflare/vitest-pool-workers, miniflare and wrangler in your project. npm why miniflare will help you find different installations of miniflare in your monorepo, to make sure they're all up-to-date.

@awais-codes
Copy link

Thanks. I updated wrangler, @cloudflare/vitest-pool-workers and @cloudflare/workers-types and it worked like a charm.

@Xvezda
Copy link
Author

Xvezda commented Mar 31, 2024

Runs pnpm update wrangler @cloudflare/vitest-pool-workers @cloudflare/workers-types seems resolving the issue.
Thanks alot.

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

No branches or pull requests

3 participants