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

[Script] Use __non_webpack_require__ to fetch partytown server-side #35793

Merged
merged 1 commit into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1573,7 +1573,6 @@ export default async function getBaseWebpackConfig(
webpack5Config.module!.parser = {
javascript: {
url: 'relative',
commonjsMagicComments: true,
},
}
webpack5Config.module!.generator = {
Expand Down
11 changes: 7 additions & 4 deletions packages/next/pages/_document.tsx
Expand Up @@ -85,7 +85,8 @@ function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) {
try {
let {
partytownSnippet,
} = require(/* webpackIgnore: true */ '@builder.io/partytown/integration'!)
// @ts-ignore: Prevent webpack from processing this require
} = __non_webpack_require__('@builder.io/partytown/integration'!)

const children = Array.isArray(props.children)
? props.children
Expand Down Expand Up @@ -135,9 +136,11 @@ function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) {
</>
)
} catch (err) {
console.warn(
`Warning: Partytown could not be instantiated in your application due to an error. ${err}`
)
if (isError(err) && err.code !== 'MODULE_NOT_FOUND') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijjk We already throw an error if the package is missing. Was a little noisy showing additional error messages hence why I included this condition.

console.warn(
`Warning: Partytown could not be instantiated in your application due to an error. ${err.message}`
)
}
return null
}
}
Expand Down