-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Running the parser in a vercel edge function #736
Comments
@sylvesteraswin Yes, it should be possible since this library can be run on both the server and client-side. See Node.js demo. |
@remarkablemark thanks for your quick reply, I am referring to Vercel Edge functions. Looks like it does not support most of the Node.JS APIs. Here is my example // /api/sample.tsx
export const config = {
runtime: "experimental-edge",
};
const handler = async (req: NextRequest) => {
const element = reactParser(`<html></html>`, {});
return element;
}
export default handler; This is the below error I get [Error: This browser does not support `document.implementation.createHTMLDocument`] |
Thanks for the response. It seems like Vercel Edge functions is using the |
I am also facing this issue, but just using server-side components in Next.js 13 :(
returns:
|
@Jahrhause do you have a custom webpack config? |
Yes I do, this is what I have:
|
@Jahrhause I think the |
@remarkablemark ahh that fixed the issue, sorry about that :) |
@remarkablemark Hey! I have the same problem in Vercel Edge Functions, though I have default webpack config (Next.js 13).
In the logs I see it calls the Thanks! |
Can someone help me create a reproducible example (e.g., public repository) so I can take a look? |
Running into this as well. I'm using Vercel's og image library (which runs in vercel edge functions) to generate OG images for rich text posts. I'd like to use this library to turn HTML into JSX and use it in the og image. Here is a github repo you can use to reproduce. It's pretty simple:
You should run into it every time. |
I confirm this issues still exists and it's can be a hudge problem, because if the error popup
|
This may be an issue on Vercel since it seems to be using the browser module of Also, I'd like everyone to check that they're not setting the |
@grantmagdanz can you share the link to your GitHub repo? |
Oh sorry here it is: https://github.com/grantmagdanz/vercel-og-nextjs |
@grantmagdanz I was able to fix the server error by updating the Webpack config in const path = require('path');
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
webpack: (config) => {
config.module.rules = [
...config.module.rules,
{
test: /html-react-parser\/index\.js$/,
resolve: {
alias: {
'html-dom-parser': path.join(path.dirname(require.resolve('html-dom-parser')), 'server/html-to-dom.js'),
},
},
},
];
return config;
},
} |
Given this server error seems to be coming from Vercel/Webpack/PNPM and not from this library, I'm going to close this issue as won't do. |
@remarkablemark It seems that the solution that was effective before now no longer works. First, I updated to the latest version, 5.1.9. Also, I noticed that the path you used, |
@remarkablemark I think it's not because of the URL issue; I corrected the URL, and yet, it still reports, |
@j4tmr can you open |
@remarkablemark Thank you for your reply. I tested it again today, and my webpack code is like this.
I console.logged the URL, and the result looks like this. |
@remarkablemark |
Hello,
Is it possible to run the parser in an edge function? I am trying to convert static HTML string to a react object in a vercel edge function.
Thanks
Sylvester
The text was updated successfully, but these errors were encountered: