[Astro] Edge function crashing build since yesterday

Build has been crashing since yesterday. It was working fine before. what could be the cause?

{
  "name": "@example/minimal",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro build && gulp",
    "preview": "astro preview",
    "astro": "astro",
    "test": "vitest run"
  },
  "devDependencies": {
    "@astrojs/sitemap": "^1.0.0",
    "@astrojs/tailwind": "^4.0.0",
    "@astrojs/vue": "^1.0.0",
    "@types/intercom-web": "^2.8.18",
    "@types/ua-parser-js": "^0.7.37",
    "astro": "^2.6.0",
    "gulp": "^4.0.2",
    "gulp-clean-css": "^4.3.0",
    "gulp-minify": "^3.1.0",
    "husky": "^8.0.3",
    "prettier": "^2.7.1",
    "prettier-plugin-astro": "^0.5.0",
    "sass": "^1.54.4",
    "vitest": "^0.23.4",
    "vue": "^3.2.30"
  },
  "dependencies": {
    "@astrojs/netlify": "^2.3.0",
    "@astrojs/partytown": "^2.0.0",
    "@headlessui/vue": "^1.6.7",
    "@nanostores/vue": "^0.5.5",
    "@splidejs/splide": "^4.1.4",
    "@tailwindcss/custom-forms": "^0.2.1",
    "@vueuse/components": "^9.1.1",
    "@vueuse/core": "^9.1.1",
    "astro-seo": "^0.6.0",
    "astro-seo-schema": "^2.2.0",
    "floating-vue": "^2.0.0-beta.19",
    "js-base64": "^3.7.5",
    "lazysizes": "^5.3.2",
    "nanostores": "^0.6.0",
    "swrv": "^1.0.0-beta.8",
    "tailwindcss": "^3.3.2",
    "ua-parser-js": "^1.0.36",
    "vue-awesome-paginate": "^1.1.46",
    "vue-exit-intent": "^2.0.0",
    "vue-imask": "^6.4.2",
    "vueperslides": "^3.5.1"
  }
}

Logs

11:23:03 AM: @astrojs/sitemap: `sitemap-index.xml` is created.
11:23:03 AM: 05:53:03 AM [build] Server built in 8.80s
11:23:03 AM: 05:53:03 AM [build] Complete!
11:23:03 AM: [05:53:03] Using gulpfile /opt/build/repo/gulpfile.js
11:23:03 AM: [05:53:03] Starting "default"...
11:23:03 AM: [05:53:03] Starting "compressJs"...
11:23:03 AM: Compressing scripts in => ./dist/scripts/*.js
[05:53:03] Finished "compressJs" after 126 ms
11:23:03 AM: [05:53:03] Finished "default" after 127 ms
11:23:03 AM: Done in 10.26s.
11:23:03 AM: ​
11:23:03 AM: (build.command completed in 10.5s)
11:23:03 AM: ​
11:23:03 AM: Edge Functions bundling                                       
11:23:03 AM: ────────────────────────────────────────────────────────────────
11:23:03 AM: ​
11:23:03 AM: Packaging Edge Functions from .netlify/edge-functions directory:
11:23:03 AM:  - _empty-middleware
11:23:03 AM:  - entry
11:23:03 AM:  - renderers
11:23:04 AM: error: Uncaught (in promise) Error: Error: Could not find file: file:///opt/build/repo/.netlify/edge-functions/chunks/astro.f7dc36d4.mjs
11:23:04 AM:       const ret = new Error(getStringFromWasm0(arg0, arg1));
11:23:04 AM:                   ^
11:23:04 AM:     at __wbg_new_15d3966e9981a196 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:417:19)
11:23:04 AM:     at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:93412)
11:23:04 AM:     at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1499594)
11:23:04 AM:     at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1938165)
11:23:04 AM:     at __wbg_adapter_40 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:231:6)
11:23:04 AM:     at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:215:14)
11:23:04 AM:     at eventLoopTick (ext:core/01_core.js:183:11)
11:23:04 AM: ​
11:23:04 AM: Bundling of edge function failed                              
11:23:04 AM: ────────────────────────────────────────────────────────────────
11:23:04 AM: ​
11:23:04 AM:   Error message
11:23:04 AM:   Command failed with exit code 1: deno run --allow-all --no-config --import-map=/opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/import_map.json --quiet /opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/bundle.ts {"basePath":"/opt/build/repo","destPath":"/tmp/edge-65263815c09e630527d3ddbc/86281f9f-c4c9-49a5-a8d3-710b7566d6c2.eszip","externals":[],"functions":[{"name":"_empty-middleware","path":"/opt/build/repo/.netlify/edge-functions/_empty-middleware.mjs"},{"name":"entry","path":"/opt/build/repo/.netlify/edge-functions/entry.js"},{"name":"renderers","path":"/opt/build/repo/.netlify/edge-functions/renderers.mjs"}],"importMapData":"{\"imports\":{\"@netlify/edge-functions\":\"https://edge.netlify.com/v1/index.ts\",\"netlify:edge\":\"https://edge.netlify.com/v1/index.ts?v=legacy\"},\"scopes\":{}}"} (https://ntl.fyi/exit-code-1)
11:23:04 AM:   error: Uncaught (in promise) Error: Error: Could not find file: file:///opt/build/repo/.netlify/edge-functions/chunks/astro.f7dc36d4.mjs
11:23:04 AM:         const ret = new Error(getStringFromWasm0(arg0, arg1));
11:23:04 AM:                     ^
11:23:04 AM:       at __wbg_new_15d3966e9981a196 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:417:19)
11:23:04 AM:       at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:93412)
11:23:04 AM:       at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1499594)
11:23:04 AM:       at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1938165)
11:23:04 AM:       at __wbg_adapter_40 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:231:6)
11:23:04 AM:       at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:215:14)
11:23:04 AM:       at eventLoopTick (ext:core/01_core.js:183:11)
11:23:04 AM: ​
11:23:04 AM:   Error location
11:23:04 AM:   While bundling edge function
11:23:04 AM: ​
11:23:04 AM:   Resolved config
11:23:04 AM:   build:
11:23:04 AM:     command: yarn build
11:23:04 AM:     commandOrigin: ui
11:23:04 AM:     environment:
11:23:04 AM:       - DEPRECATED
11:23:04 AM:       - NETLIFY_USE_YARN
11:23:04 AM:       - PUBLIC_API_BASE_URL
11:23:04 AM:       - PUBLIC_APP_URL
11:23:04 AM:       - PUBLIC_CDN_BASE_URL
11:23:04 AM:       - PUBLIC_GTM_ID
11:23:04 AM:       - PUBLIC_IMAGE_CDN_BASE_KEY_PATH
11:23:04 AM:       - PUBLIC_IMAGE_CDN_BUCKET
11:23:04 AM:       - PUBLIC_IMAGE_CDN_URL
11:23:04 AM:       - PUBLIC_OPEN_GRAPH_BASE_URL
11:23:04 AM:     publish: /opt/build/repo/dist
11:23:04 AM:     publishOrigin: ui
11:23:04 AM:   headers:
11:23:04 AM:     - for: "*"
11:23:04 AM:       values:
11:23:04 AM:         Content-Security-Policy: frame-ancestors "none";
11:23:04 AM:         Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
11:23:04 AM:         X-Content-Type-Options: nosniff
11:23:04 AM:         X-Frame-Options: DENY
11:23:04 AM:         X-XSS-Protection: 1; mode=block
11:23:04 AM:   headersOrigin: config
11:23:04 AM:   redirects:
11:23:04 AM:     - force: true
11:23:13 AM: Failed during stage "building site": Build script returned non-zero exit code: 2
11:23:13 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:23:13 AM: Failing build: Failed to build site
11:23:13 AM: Finished processing build request in 51.108s

Hi! We already spotted this error popping up in our build logs yesterday and started debugging it. We believe it’s caused by a bug within Astro’s integration with Netlify.

In our repro, this only ocurred on Astro v2 and was resolved after upgrading to Astro v3 and the v3 of @astrojs/netlify. Could you try upgrading and check if that resolves it for you, as well?

As a heads-up, upgrading to @astrojs/netlify seems to change a bit about their API, and you’ll need to pass the edgeMiddleware: true parameter:

- import netlify from "@astrojs/netlify/edge-functions";
+ import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: netlify({
+    edgeMiddleware: true
  })
});

@skn0tt Just did the upgrade. The build is working fine now but I’m getting this error on the deployed site.

Function log

Oct 11, 01:32:14 PM: INIT_START Runtime Version: nodejs:18.v13	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:0229ff5ced939264450549058d8f267110e92677c27063e6dcd781a280f2462b
Oct 11, 01:32:14 PM: d6c00543 INFO   {
  ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
}
Oct 11, 01:32:14 PM: d6c00543 INFO   { type: undefined }
Oct 11, 01:32:14 PM: d6c00543 WARN   [Vue warn]: Unhandled error during execution of setup function 
  at <SearchBox isMobile=false data-astro-cid-j7pv25f6=true >
Oct 11, 01:32:15 PM: d6c00543 ERROR  Invoke Error 	{"errorType":"TypeError","errorMessage":"useSWRV is not a function","stack":["TypeError: useSWRV is not a function","    at setup (file:///var/task/.netlify/functions-internal/chunks/pages/__becbae95.mjs:2239:91)","    at _sfc_main.setup (file:///var/task/.netlify/functions-internal/chunks/pages/__becbae95.mjs:2559:23)","    at callWithErrorHandling (/var/task/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:156:18)","    at setupStatefulComponent (/var/task/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7190:25)","    at setupComponent (/var/task/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7151:36)","    at renderComponentVNode (/var/task/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:614:15)","    at renderVNode (/var/task/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:743:14)","    at renderComponentSubTree (/var/task/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:698:7)","    at renderComponentVNode (/var/task/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:631:12)","    at renderToString (/var/task/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:902:24)"]}
Oct 11, 01:32:15 PM: d6c00543 Duration: 241.92 ms	Memory Usage: 108 MB	Init Duration: 487.15 ms

Good to hear the build is working now!

The error message seems to be caused by something in your site, not by the Netlify build process. It looks like it’s internal to Vue.js, maybe related to GitHub - Kong/swrv: Stale-while-revalidate data fetching for Vue?

If you want to debug this, i’d recommend you take a look at the source code that’s referenced in the stack trace. You can inspect this locally by running netlify build in your repo - then you should have the .netlify/functions-internal folder populated with these files.

1 Like

It works locally though. The package is referenced properly in the package.json file too. Don’t know why it isn’t getting the package on the deployed site. I’ll look into it. Meanwhile if you find anything related to it, please let me know.

Also is there any way to fix the netlify build process without upgrading astro and netlify adapter?

This is not a bug within the Netlify Build process, but within Astro’s adapter for Netlify. It was fixed in the upgraded version of Astro and the Netlify Adapter, so you’ll have to upgrade.

The package is referenced properly in the package.json file too. Don’t know why it isn’t getting the package on the deployed site.

If you think this might be a bug within Netlify’s bundling, then I’d be very happy about a reproduction case that I can use to look at the bug! A zip file would already be super valuable.

So I did the netlify build locally, and I went to the mentioned line that was giving error.

Here the useSWRV is being called, and the import for this is also present at the top of the current file

Why is it still undefined? Is there any config in netlify where I could tell to include this package please.

Did you configure any special bundler within netlify.toml?

If not, please provide me with a reproduction case and i’ll take a look at what’s going on.

This is the netlify.toml

[[headers]]
  for = "*"
  [headers.values]
    X-Frame-Options = "DENY"
    Content-Security-Policy = "frame-ancestors 'none';"
    X-XSS-Protection = "1; mode=block"
    X-Content-Type-Options = "nosniff"
    Strict-Transport-Security = "max-age=63072000; includeSubDomains; preload"

Really hard to provide a reproduction case since its a production site. I’ll see what I can do !

Interesting. I don’t know what then caused it to stopped working suddenly. We didn’t change any package related to astro and its netlify adapter.

Update:

[1]: Some more digging. I tried running netlify build locally and netlify dev to preview locally. The netlify dev command runs succesfully and opens up two ports. localhost:4321 and localhost:8888. The localhost:4321 port works fine. There is issues with the localhost:8888 where it gives the useSWRV is not a function error.

[2]: Migrated to cloudfare for now. Everything seems to be working fine there. Will update if I get any fix with netlify.

Update:

[3] So the vue component that was giving the error was changed from <Component client:load /> to <Component client:only="vue" />. This seems to have fixed the error on netlify.