netlify / cli

Netlify Command Line Interface
http://cli.netlify.com
MIT License
1.58k stars 352 forks source link

netlify build fails to bundle edge function #5923

Closed maddsua closed 1 year ago

maddsua commented 1 year ago

Describe the bug

Current version of the CLI uses @netlify/build 29.17.3 which fails to bundle any edge function in production mode.

Error log:

C:\Users\maddsua\Desktop\New folder>ntl build
​
Netlify Build
────────────────────────────────────────────────────────────────
​
> Version
  @netlify/build 29.17.3
​
> Flags
  dry: false
  offline: false
​
> Current directory
  C:\Users\maddsua\Desktop\New folder
​
> Config file
  No config file was defined: using default values.
​
> Context
  production
​
Edge Functions bundling
────────────────────────────────────────────────────────────────
​
Packaging Edge Functions from netlify\edge-functions directory:
 - hello
Could not load configuration for edge function at 'C:\Users\maddsua\Desktop\New folder\netlify\edge-functions\hello.js'
error: Uncaught (in promise) SyntaxError: The requested module '../log/logger.ts' does not provide an export named 'deta
chedLogger' at https://edge.netlify.com/bootstrap/util/redirect.ts:3:10
const { Netlify } = await import(bootstrapURL)
                    ^
    at async file:///C:/Users/maddsua/AppData/Roaming/nodejs/node_modules/netlify-cli/node_modules/@netlify/edge-bundler
/deno/config.ts:4:21
​
(Edge Functions bundling completed in 2.7s)
​
Netlify Build Complete
────────────────────────────────────────────────────────────────
​
(Netlify Build completed in 2.7s)

Example edge function:

//netlify/edge-functions/hello.js

export default () => new Response("Hello world");

export const config = { path: "/test" };

Edge functions seem work fine in dev mode, this only happens when trying to build for production.

This is just a reproduction example to keep things simple, the issue can be seen in other projects too.

Steps to reproduce

  1. Download and extract this example project (or just create a new one with an edge function, does not really matter)
  2. Try building it with netlify build
  3. Get an error on edge functions bundle stage

example.zip

Configuration

A totally blank configuration, just a single example edge function in a project.

Environment

System: OS: Windows 10 10.0.19043 Binaries: Node: 18.12.1 - ~\AppData\Roaming\nodejs\node.EXE npm: 9.7.2 - ~\AppData\Roaming\nodejs\npm.CMD

Skn0tt commented 1 year ago

Hi @maddsua! I'll be looking into this. My hunch is that Deno (the runtime we use to execute edge functions) cached an old version of edge.netlify.com locally. Could you try running deno cache --reload https://edge.netlify.com, and see if that fixes the issue?

Skn0tt commented 1 year ago

Forget that, it looks like deno cache --reload doesn't mutate the global cache, but only the local one. Working on a fix! Thanks for opening the issue and bringing this to our attention!

Skn0tt commented 1 year ago

Once https://github.com/netlify/build/pull/5221 is released, we can pass in getBootstrapURL() here:

https://github.com/netlify/cli/blob/b029a888358ef6d05dbc62e7d00330d0daee6e58/src/utils/run-build.mjs#L39-L58

frankroc2022 commented 1 year ago

Last working version for me is 15.2.0. What I have to change to use a later version?

maddsua commented 1 year ago

Last working version for me is 15.2.0. What I have to change to use a later version?

Looks like @Skn0tt added changes to the future version, now we just wait, I don't see anything we can do as users/customers. If you have build minutes left, you might use cloud builds instead of building locally for the time being.

Skn0tt commented 1 year ago

Sorry for the delay, yeah. I'm expecting a version with a fix to land today or tomorrow.

Skn0tt commented 1 year ago

The fix was released as part of v16.0.1. It fixed it for me, so I hope it also does for you :) If it doesn't feel free to ping & reopen the issue.

maddsua commented 1 year ago

Can confirm, it's working again after updating to v16.0.1. @Skn0tt thank you very much!

frankroc2022 commented 11 months ago

Last working version for me is 15.2.0. What I have to change to use a later version?

Still the same. I tested latest version v17.1.0 and v16.0.1.