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 and AstroContainer throw error after 4.13.3 #11906

Open
1 task
zanettin opened this issue Sep 3, 2024 · 2 comments
Open
1 task

Vitest and AstroContainer throw error after 4.13.3 #11906

zanettin opened this issue Sep 3, 2024 · 2 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: container Related to the container API (scope)

Comments

@zanettin
Copy link

zanettin commented Sep 3, 2024

Astro Info

Astro                    v4.13.4
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The attached stackblitz example works till astro v4.13.3. When upgrading to 4.13.4 or higher, the vitest are throwing this error:

ReferenceError: crypto is not defined
 ❯ Module.createKey node_modules/astro/dist/core/encryption.js:5:15
      4|   const key = await crypto.subtle.generateKey(
      5|     {
      6|       name: ALGORITHM,
       |         ^
      7|       length: 256
      8|     },
 ❯ createManifest node_modules/astro/dist/container/index.js:48:32
 ❯ new experimental_AstroContainer node_modules/astro/dist/container/index.js:75:17
 ❯ experimental_AstroContainer.create node_modules/astro/dist/container/index.js:104:12
 ❯ eval src/components/Card.test.ts:9:23
 ❯ runTest node_modules/@vitest/runner/dist/index.js:995:11
 ❯ runSuite node_modules/@vitest/runner/dist/index.js:1151:15
 ❯ runSuite node_modules/@vitest/runner/dist/index.js:1151:15
 ❯ runFiles node_modules/@vitest/runner/dist/index.js:1208:5

Reproduction Steps

  • change astro version to 4.13.4 or higher (latest working version is 4.13.3)
  • run npm install
  • run npm test

What's the expected result?

The tests are working again and/or docs are updated 👼

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-dpyy1r?file=package.json

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 3, 2024
@jsparkdev
Copy link

jsparkdev commented Sep 3, 2024

It works well locally under the same conditions. Have you tried it locally?
In my case, it works successfully locally, and I get the same error as you on Stackblitz.

I overlooked that my local project uses the latest version of Node.
As @Princesseuh said, it seems that this problem can be solved by installing Node 20 or higher.

@Princesseuh
Copy link
Member

Princesseuh commented Sep 3, 2024

This is because Node 18 doesn't have crypto globally available, Astro normally applies polyfill for this, but it seems like they don't apply correctly here. Updating to Node 20 or later would workaround the issue.

@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) feat: container Related to the container API (scope) and removed needs triage Issue needs to be triaged labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: container Related to the container API (scope)
Projects
None yet
Development

No branches or pull requests

4 participants
@Princesseuh @zanettin @jsparkdev and others