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]: Could not map all functions to an entry in the middleware manifest #244

Closed
1 task done
felix-schultz opened this issue May 14, 2023 · 7 comments · Fixed by #246
Closed
1 task done
Labels
bug Something isn't working

Comments

@felix-schultz
Copy link
Contributor

next-on-pages environment related information

System:
        Platform: darwin
        Arch: arm64
        Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
        CPU: (10) arm64 Apple M1 Max
        Memory: 32 GB
        Shell: /bin/zsh
Binaries:
        Node: 19.0.0
        Yarn: N/A
        npm: 8.19.2
        pnpm: N/A
Package Manager Used: npm
Relevant Packages:
        @cloudflare/next-on-pages: 0.10.1
        vercel: N/A
        next: N/A

Description

When trying to build with npx @cloudflare/next-on-pages --experimental-minify I am getting the error:
⚡️ ERROR: Could not map all functions to an entry in the middleware manifest.

The output folder looks fine to me too, however I suspect there is a worker.js file missing that enables the functions in the first place. The deployment via wrangler also shows the static assets, while the functions are missing completely.

Reproduction

No response

Pages Deployment Method

Direct Upload (wrangler pages publish or the @cloudflare/pages-action GitHub Action)

Pages Deployment ID

No response

Additional Information

Output log:

▲  Route (app)                                Size     First Load JS
▲  ┌ ℇ /                                      745 B           404 kB
▲  ├ ℇ /eula                                  1.17 kB        85.9 kB
▲  ├ ℇ /legal-notice                          1.17 kB        85.9 kB
▲  ├ ℇ /login                                 881 B           404 kB
▲  ├ ℇ /privacy-policy                        1.17 kB        85.9 kB
▲  ├ ℇ /settings                              167 B          77.5 kB
▲  ├ ℇ /settings                              167 B          77.5 kB
▲  ├ ℇ /settings                              167 B          77.5 kB
▲  ├ ℇ /settings/billing                      0 B                0 B
▲  ├ ℇ /settings/billing                      0 B                0 B
▲  ├ ℇ /settings/developer                    0 B                0 B
▲  ├ ℇ /settings/developer                    0 B                0 B
▲  ├ ℇ /settings/notification                 0 B                0 B
▲  ├ ℇ /settings/notification                 0 B                0 B
▲  ├ ℇ /settings/privacy                      0 B                0 B
▲  ├ ℇ /settings/privacy                      0 B                0 B
▲  ├ ℇ /settings/profile                      0 B                0 B
▲  ├ ℇ /settings/profile                      0 B                0 B
▲  ├ ℇ /settings/storage                      0 B                0 B
▲  ├ ℇ /settings/storage                      0 B                0 B
▲  ├ ℇ /settings/subscription                 0 B                0 B
▲  ├ ℇ /settings/subscription                 0 B                0 B
▲  ├ ℇ /settings/usage                        0 B                0 B
▲  └ ℇ /settings/usage                        0 B                0 B
▲  + First Load JS shared by all              77.3 kB
▲  ├ chunks/253-d9f504f8f620858c.js         24.5 kB
▲  ├ chunks/6b645fa8-5c940de39a313a0d.js    50.5 kB
▲  ├ chunks/main-app-b8b5439f916e9ad1.js    215 B
▲  └ chunks/webpack-f1d4f8cbe4f57b73.js     2.06 kB
▲  
▲  Route (pages)                              Size     First Load JS
▲  ─ ○ /404                                   179 B          86.5 kB
▲  + First Load JS shared by all              86.3 kB
▲  ├ chunks/main-1d27128c79c25202.js        84 kB
▲  ├ chunks/pages/_app-7fb87454d03f3d10.js  193 B
▲  └ chunks/webpack-f1d4f8cbe4f57b73.js     2.06 kB
▲  
▲  ƒ Middleware                               23.9 kB
▲  ℇ  (Streaming)  server-side renders with streaming (uses React 18 SSR streaming or Server Components)
▲  ○  (Static)     automatically rendered as static HTML (uses no initial props)
▲  Traced Next.js server files in: 13.862ms
▲  Created all serverless functions in: 16.737s
▲  Collected static files (public/, static/, .next/static): 9.708ms
▲  Using TypeScript 4.9.3 (local user-provided)
▲  Build Completed in .vercel/output [3m]
⚡️ Completed `npx vercel build`.
⚡️ ⚡️ ERROR: Could not map all functions to an entry in the middleware manifest.
⚡️ Please report this at https://github.com/cloudflare/next-on-pages/issues.

I am trying to use the new parallel rendering feature.

Would you like to help?

  • Would you like to help fixing this bug?
@felix-schultz felix-schultz added the bug Something isn't working label May 14, 2023
@james-elicx
Copy link
Contributor

Hello, would it be possible for you to try building with the beta release of next-on-pages (@cloudflare/next-on-pages@beta)? There's a chance that your issue might have already been addressed with one of the fixes we've made.

If you are still seeing a problem generating a worker file with the beta release, it would be very much appreciated if some sort of minimal reproduction could be provided 🙂

@felix-schultz
Copy link
Contributor Author

Thank you very much for your quick answer! I am getting a way more verbose error now -> progress :)

Could not resolve "node:events"

The package "node:events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

I am now investigating where this error comes from (running in edge-runtime locally does not error).

@james-elicx
Copy link
Contributor

Thank you very much for your quick answer! I am getting a way more verbose error now -> progress :)

Could not resolve "node:events"

The package "node:events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

I am now investigating where this error comes from (running in edge-runtime locally does not error).

Is this occurring when deploying to Pages/using Wrangler @felix-schultz? If you haven't already, please ensure that you add the nodejs_compat compatibility flag in your Pages project settings, and if using Wrangler locally, pass the flag to it.

If that doesn't do the trick and you can't identify the cause, I'm happy to investigate this if you have a reproduction. 🙂

@felix-schultz
Copy link
Contributor Author

I am getting the error for npx @cloudflare/next-on-pages --experimental-minify after the vercel build command is called. Somehow when calling vercel build manually, I am not getting any error.

The resulting output has a static and functions folder. However after publishing with wrangler publish, no functions are being deployed. No error too. And the functions folder is also not just uploaded as a file directory, so something happens, but without any errors or logs it is hard to tell where things break.

Will continue working on this problem tomorrow. There has to be a way to get this to work.

@felix-schultz
Copy link
Contributor Author

Reproduction is tricky, I don't have any clue where the problem is and the project is a huge private monorepo. I will try my best to find a way to reproduce the issue and keep you updated!

@james-elicx
Copy link
Contributor

james-elicx commented May 14, 2023

I am getting the error for npx @cloudflare/next-on-pages --experimental-minify after the vercel build command is called. Somehow when calling vercel build manually, I am not getting any error.

The resulting output has a static and functions folder. However after publishing with wrangler publish, no functions are being deployed. No error too. And the functions folder is also not just uploaded as a file directory, so something happens, but without any errors or logs it is hard to tell where things break.

Will continue working on this problem tomorrow. There has to be a way to get this to work.

If you get the error running next-on-pages @felix-schultz, it won't be able to build a worker file to publish to Pages.

The functions directory that Vercel builds (.vercel/output/functions) is what we process in order to create our worker file. - the presence of the functions folder does not indicate a successful build for next-on-pages. Rather, it just indicates that the Vercel build output was built successfully.

The static directory (.vercel/output/static) is also generated by Vercel and is where we build our worker file to, inside the _worker.js directory, along with functions that have the webpack chunks extracted and deduped.

So, it sounds to me like there is something going wrong when we try to deal with either one of the webpack chunks, or functions, during processing, because our worker file build step marks node:* as external. The other two parts only mark node:buffer as external. So, I would assume that if we were to change these other two parts in generateFunctionsMap.ts to mark node:* as external, it might successfully build your project.

My concern though, if changing the externals is the solution, is that we might need to then add another webpack plugin to deal with them, as in both of the node:buffer cases we have a webpack plugin to update the node:buffer import handling.

That's my theory anyway, I can't tell for sure without playing with a project that causes your issue.

If that does happen to be the case and you would like to open a PR for it, it'd be hugely beneficial for us if a test app can be provided with it. Since you aren't really able to share a reproduction of your current project which I understand, I would recommend searching through the source code in the functions that Vercel builds to see where node:events is used so that it can be traced back to a cause that might help make a minimal test app.

@felix-schultz
Copy link
Contributor Author

Update: I have isolated the packages that caused the node:events in the first place. Client side javascript that had nothing to-do with the edge function (and something I can not remove)

Due to your great tips (basically already explaining what to do) @james-elicx I tried to just declare node:events as external. I did not add another plugin, like you did with node:buffer. It still seems to work with my project, nothing breaking runtime.

For now I have published my own version of next-on-pages here Next-On-Pages with Node:Events in case someone else is running into this problem.

I also created a pull request; #246
Not sure if this should already be merged!

Thank you very much for your help so far 💯

dario-piotrowicz pushed a commit that referenced this issue May 15, 2023
#244 (#246)

* Added "node:events" to external config for the functionsmap generation. #244

* Wildcard node modules + Changeset

changed node:buffer, node:events -> node:*

---------

Co-authored-by: Felix Schultz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants