Unverified Commit de473366 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Revert "Support `server-only` inside pages/api" (#46388)

Looks like this is breaking when run against `vercel-site`, going to revert temporarily to allow investigating further without blocking canary. 

Reverts vercel/next.js#46328
parent dee944bb
...@@ -786,11 +786,6 @@ export default async function getBaseWebpackConfig( ...@@ -786,11 +786,6 @@ export default async function getBaseWebpackConfig(
[getSwcLoader({ isServerLayer: true }), getBabelLoader()] [getSwcLoader({ isServerLayer: true }), getBabelLoader()]
: [] : []
const loaderForAPI =
hasServerComponents && useSWCLoader
? getSwcLoader({ isServerLayer: true })
: defaultLoaders.babel
const pageExtensions = config.pageExtensions const pageExtensions = config.pageExtensions
const outputPath = const outputPath =
...@@ -1414,16 +1409,6 @@ export default async function getBaseWebpackConfig( ...@@ -1414,16 +1409,6 @@ export default async function getBaseWebpackConfig(
}, },
} }
const serverCondition = [
'react-server',
...mainFieldsPerCompiler[
isEdgeServer ? COMPILER_NAMES.edgeServer : COMPILER_NAMES.server
],
'node',
'import',
'require',
]
let webpackConfig: webpack.Configuration = { let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined, parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
...(isNodeServer ? { externalsPresets: { node: true } } : {}), ...(isNodeServer ? { externalsPresets: { node: true } } : {}),
...@@ -1736,7 +1721,17 @@ export default async function getBaseWebpackConfig( ...@@ -1736,7 +1721,17 @@ export default async function getBaseWebpackConfig(
], ],
}, },
resolve: { resolve: {
conditionNames: serverCondition, conditionNames: [
'react-server',
...mainFieldsPerCompiler[
isEdgeServer
? COMPILER_NAMES.edgeServer
: COMPILER_NAMES.server
],
'node',
'import',
'require',
],
alias: { alias: {
// If missing the alias override here, the default alias will be used which aliases // If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition // react to the direct file path, not the package name. In that case the condition
...@@ -1862,6 +1857,14 @@ export default async function getBaseWebpackConfig( ...@@ -1862,6 +1857,14 @@ export default async function getBaseWebpackConfig(
}, },
] ]
: []), : []),
{
test: /\.(js|cjs|mjs)$/,
issuerLayer: WEBPACK_LAYERS.api,
parser: {
// Switch back to normal URL handling
url: true,
},
},
{ {
oneOf: [ oneOf: [
{ {
...@@ -1871,12 +1874,7 @@ export default async function getBaseWebpackConfig( ...@@ -1871,12 +1874,7 @@ export default async function getBaseWebpackConfig(
// Switch back to normal URL handling // Switch back to normal URL handling
url: true, url: true,
}, },
resolve: { use: defaultLoaders.babel,
alias: {
'server-only': 'next/dist/compiled/server-only/empty',
},
},
use: loaderForAPI,
}, },
{ {
...codeCondition, ...codeCondition,
......
...@@ -13,7 +13,6 @@ createNextDescribe( ...@@ -13,7 +13,6 @@ createNextDescribe(
react: 'latest', react: 'latest',
'react-dom': 'latest', 'react-dom': 'latest',
sass: 'latest', sass: 'latest',
'server-only': 'latest',
}, },
}, },
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => { ({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
...@@ -68,11 +67,6 @@ createNextDescribe( ...@@ -68,11 +67,6 @@ createNextDescribe(
}) })
} }
it('should support server-only in pages/api', async () => {
const res = await next.fetch('/api/server-only')
expect(await res.text()).toBe('Hello from server-only.js')
})
if (!isNextDeploy) { if (!isNextDeploy) {
it('should not share edge workers', async () => { it('should not share edge workers', async () => {
const controller1 = new AbortController() const controller1 = new AbortController()
......
import 'server-only'
export default function (_, res) {
res.end('Hello from server-only.js')
}
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