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

Fix: revert the bad node binary handling #71723

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,17 +1291,14 @@ export default async function getBaseWebpackConfig(
or: WEBPACK_LAYERS.GROUP.neutralTarget,
},
},
{
test: /[\\/].*?\.node$/,
loader: isNodeServer
? 'next-server-binary-loader'
: 'next-error-browser-binary-loader',
// On server side bundling, only apply to app router, do not apply to pages router;
// On client side or edge runtime bundling, always error.
...(isNodeServer && {
issuerLayer: isWebpackBundledLayer,
}),
},
...(isNodeServer
? []
: [
{
test: /[\\/].*?\.node$/,
loader: 'next-error-browser-binary-loader',
},
]),
...(hasAppDir
? [
{
Expand Down
lubieowoce marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default function nextErrorBrowserBinaryLoader(
if (!relativePath.startsWith('.')) {
relativePath = './' + relativePath
}
// FIXME: the path resolving is not robust
return `module.exports = __non_webpack_require__(${JSON.stringify(relativePath)})`
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ import {
getRedboxDescription,
getRedboxSource,
} from 'next-test-utils'
;(process.env.TURBOPACK ? describe.skip : describe)(
'externalize-node-binary-browser-error',
() => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should error when import node binary on browser side', async () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}
// FIXME: er-enable when we have a better implementation of node binary resolving
describe.skip('externalize-node-binary-browser-error', () => {
const { next } = nextTestSetup({
files: __dirname,
})

expect(redbox.description).toBe('Failed to compile')
expect(redbox.source).toMatchInlineSnapshot(`
it('should error when import node binary on browser side', async () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}

expect(redbox.description).toBe('Failed to compile')
expect(redbox.source).toMatchInlineSnapshot(`
"./node_modules/foo-browser-import-binary/binary.node
Error: Node.js binary module ./node_modules/foo-browser-import-binary/binary.node is not supported in the browser. Please only use the module on server side"
`)
})
}
)
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { nextTestSetup } from 'e2e-utils'

describe('externalize-node-binary', () => {
// FIXME: er-enable when we have a better implementation of node binary resolving
describe.skip('externalize-node-binary', () => {
const { next } = nextTestSetup({
files: __dirname,
})
Expand Down
Loading