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

Tests type error when using [assets] in wrangler.toml #793

Open
dstr89 opened this issue Dec 18, 2024 · 2 comments
Open

Tests type error when using [assets] in wrangler.toml #793

dstr89 opened this issue Dec 18, 2024 · 2 comments

Comments

@dstr89
Copy link

dstr89 commented Dec 18, 2024

Hello,

After adding the following configuration to expose public assets in my wrangler.toml

[assets]
directory = "./dist"
binding = "ASSETS"

I am getting the following error while running npm run test:

TypeError: Cannot read properties of undefined (reading 'digest')
 ❯ hashPath node_modules/miniflare/dist/src/index.js:7772:62
 ❯ node_modules/miniflare/dist/src/index.js:7707:11
 ❯ walk node_modules/miniflare/dist/src/index.js:7681:3
 ❯ buildAssetManifest node_modules/miniflare/dist/src/index.js:7671:42
 ❯ Object.getServices node_modules/miniflare/dist/src/index.js:7589:56
 ❯ Miniflare2.#assembleConfig node_modules/miniflare/dist/src/index.js:9840:42
 ❯ Miniflare2.#assembleAndUpdateConfig node_modules/miniflare/dist/src/index.js:9940:20
 ❯ Mutex.runWith node_modules/miniflare/dist/src/index.js:3632:16
 ❯ Miniflare2.#waitForReady node_modules/miniflare/dist/src/index.js:10042:5

Here is my package JSON:

{
  "name": "my-on-page-app-worker",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "vite build",
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest",
    "cf-typegen": "wrangler types"
  },
  "dependencies": {
    "preact": "^10.22.1"
  },
  "devDependencies": {
    "@cloudflare/vitest-pool-workers": "^0.5.2",
    "@cloudflare/workers-types": "^4.20241216.0",
    "@preact/preset-vite": "^2.9.0",
    "@types/node": "^22.8.1",
    "eslint": "^8.57.1",
    "eslint-config-preact": "^1.5.0",
    "miniflare": "^3.20241205.0",
    "typescript": "^5.5.2",
    "vite": "^5.3.3",
    "vite-plugin-css-injected-by-js": "^3.5.2",
    "vitest": "2.1.8",
    "wrangler": "^3.60.3"
  }
}

I noticed that the error goes away if I empty my ASSETS folder. However, then I cannot write an appropriate test. Please advise.

Daniel

@andyjessop
Copy link

@dstr89 thanks for reporting this, and sorry that you're experiencing this problem. I've tried to reproduce this locally, but I don't see the same error that you are seeing. Is there any way you could get us a minimal reproduction to debug?

@dstr89
Copy link
Author

dstr89 commented Dec 19, 2024

Hi @andyjessop, sure, here it is: https://github.com/dstr89/cloudflare-vitest-assets-issue. Steps to reproduce are in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants