Unverified Commit b19f0980 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix: revert the bad node binary handling (#72356)

backport #71723
parent c7f7de96
...@@ -1192,7 +1192,6 @@ export default async function getBaseWebpackConfig( ...@@ -1192,7 +1192,6 @@ export default async function getBaseWebpackConfig(
'next-metadata-route-loader', 'next-metadata-route-loader',
'modularize-import-loader', 'modularize-import-loader',
'next-barrel-loader', 'next-barrel-loader',
'next-server-binary-loader',
'next-error-browser-binary-loader', 'next-error-browser-binary-loader',
].reduce((alias, loader) => { ].reduce((alias, loader) => {
// using multiple aliases to replace `resolveLoader.modules` // using multiple aliases to replace `resolveLoader.modules`
...@@ -1278,17 +1277,14 @@ export default async function getBaseWebpackConfig( ...@@ -1278,17 +1277,14 @@ export default async function getBaseWebpackConfig(
or: WEBPACK_LAYERS.GROUP.nonClientServerTarget, or: WEBPACK_LAYERS.GROUP.nonClientServerTarget,
}, },
}, },
{ ...(isNodeServer
test: /[\\/].*?\.node$/, ? []
loader: isNodeServer : [
? 'next-server-binary-loader' {
: 'next-error-browser-binary-loader', test: /[\\/].*?\.node$/,
// On server side bundling, only apply to app router, do not apply to pages router; loader: 'next-error-browser-binary-loader',
// On client side or edge runtime bundling, always error. },
...(isNodeServer && { ]),
issuerLayer: isWebpackAppLayer,
}),
},
...(hasAppDir ...(hasAppDir
? [ ? [
{ {
......
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path'
export default function nextErrorBrowserBinaryLoader(
this: webpack.LoaderContext<any>
) {
let relativePath = path.relative(this.rootContext, this.resourcePath)
if (!relativePath.startsWith('.')) {
relativePath = './' + relativePath
}
return `module.exports = __non_webpack_require__(${JSON.stringify(
relativePath
)})`
}
...@@ -4,26 +4,25 @@ import { ...@@ -4,26 +4,25 @@ import {
getRedboxDescription, getRedboxDescription,
getRedboxSource, getRedboxSource,
} from 'next-test-utils' } 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 () => { // FIXME: er-enable when we have a better implementation of node binary resolving
const browser = await next.browser('/') describe.skip('externalize-node-binary-browser-error', () => {
await hasRedbox(browser) const { next } = nextTestSetup({
const redbox = { files: __dirname,
description: await getRedboxDescription(browser), })
source: await getRedboxSource(browser),
}
expect(redbox.description).toBe('Failed to compile') it('should error when import node binary on browser side', async () => {
expect(redbox.source).toMatchInlineSnapshot(` const browser = await next.browser('/')
await hasRedbox(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 "./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" 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"
`) `)
}) })
} })
)
import { nextTestSetup } from 'e2e-utils' 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({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment