-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix server error by updating Next.js Webpack config #2
Conversation
``` Error: Expected <div> to have explicit "display: flex" or "display: none" if it has more than one child node. ```
test: /html-react-parser\/index\.js$/, | ||
resolve: { | ||
alias: { | ||
'html-dom-parser': path.join(path.dirname(require.resolve('html-dom-parser')), 'lib/server/html-to-dom.js'), | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without setting this alias, Vercel/Webpack/PNPM tries to resolve the html-dom-parser client module (probably due to the browser field), which seems like a bug on their end
@@ -11,6 +11,7 @@ | |||
}, | |||
"dependencies": { | |||
"@vercel/og": "latest", | |||
"html-dom-parser": "^4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although not necessary, I installed html-dom-parser
explicitly so I could do require.resolve('html-dom-parser')
to get the module path
Alternatively, you can get the path with something like but it's less deterministic and can break when version is changed:
path.join(__dirname, 'node_modules/.pnpm/[email protected]/html-dom-parser/lib/server/html-to-dom.js')
|
||
export const config = { | ||
runtime: 'edge', | ||
} | ||
|
||
export default async function handler() { | ||
const parsedText = parse('<div><p>Hello, World</p></div>') | ||
const parsedText = parse('<div style="display: flex;"><p>Hello, World</p></div>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the error:
Expected <div> to have explicit "display: flex" or "display: none" if it has more than one child node.
What is the motivation for this pull request?
Fix server error by updating Next.js Webpack config
Fixes #1
Relates to remarkablemark/html-react-parser#736 (comment)
What is the current behavior?
Server error: http://localhost:3000/api/og
What is the new behavior?
Page renders: http://localhost:3000/api/og
Checklist: