maizzle / framework

Quickly build HTML emails with Tailwind CSS.
https://maizzle.com
MIT License
1.2k stars 48 forks source link

Issue using v5 beta10 on Netlify serverless #1304

Closed d3v1an7 closed 1 month ago

d3v1an7 commented 1 month ago

My usage of Maizzle is a bit convoluted -- I'm using the Maizzle render API in a Netlify serverless function. I've switched Netlify to use ESM, but I think it's still compiling down to CJS or doing something weird.

In any case, when adding:

import { render } from '@maizzle/framework';

I get the error:

Function make-newsletter has returned an error: The "path" argument must be of type string or an instance of URL. Received undefined at fileURLToPath (node:internal/url:1461:11) at Object. (/Users/user/workspace/project/node_modules/@maizzle/framework/src/server/routes/hmr.js:8:27) at Module._compile (node:internal/modules/cjs/loader:1358:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10) at Module.load (node:internal/modules/cjs/loader:1208:32) at Function.Module._load (node:internal/modules/cjs/loader:1024:12) at Module.require (node:internal/modules/cjs/loader:1233:19) at require (node:internal/modules/helpers:179:18) at Object. (/Users/user/workspace/project/.netlify/functions-serve/make-newsletter/make-newsletter.js:1:18) at Module._compile (node:internal/modules/cjs/loader:1358:14)

It's very likely that this is a more of an issue with Netlify, but I wanted to just double check as the error seems to be pointing at some code that handles server routes, which (on the surface!!) seems like I shouldn't need when just using render.

cossssmin commented 1 month ago

This doesn't look right, the hmr.js file isn't imported in the render export. Are you perhaps importing other things too?

Btw Maizzle 5 isn't "pure" ESM, we still use and import some libraries that are CJS, not sure if that would affect Netlify in any way though.

d3v1an7 commented 1 month ago

Yeah, on a bit of a deeper dive, I reckon this is due to how Netlify bundles up 3rd party deps for serverless functions (it creates a single ~250000 line index.js file for each endpoint that contains evvvverything, and implements a custom require function, etc).

I'll close this and try spinning up Maizzle on another serverless provider instead!