Unverified Commit 5e92ae01 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix external check for non-local next import (#25518)

parent 39181c40
...@@ -176,6 +176,7 @@ const WEBPACK_RESOLVE_OPTIONS = { ...@@ -176,6 +176,7 @@ const WEBPACK_RESOLVE_OPTIONS = {
// Otherwise combined ESM+CJS packages will never be external // Otherwise combined ESM+CJS packages will never be external
// as resolving mismatch would lead to opt-out from being external. // as resolving mismatch would lead to opt-out from being external.
dependencyType: 'commonjs', dependencyType: 'commonjs',
symlinks: true,
} }
const NODE_RESOLVE_OPTIONS = { const NODE_RESOLVE_OPTIONS = {
...@@ -739,6 +740,14 @@ export default async function getBaseWebpackConfig( ...@@ -739,6 +740,14 @@ export default async function getBaseWebpackConfig(
return return
} }
if (
res.match(
/next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/
)
) {
return `commonjs ${request}`
}
// Default pages have to be transpiled // Default pages have to be transpiled
if ( if (
res.match(/[/\\]next[/\\]dist[/\\]/) || res.match(/[/\\]next[/\\]dist[/\\]/) ||
......
import Link from 'next/link' import Link from 'next/link'
import ReactDOM from 'react-dom/server'
import { RouterContext } from 'next/dist/next-server/lib/router-context'
import { useRouter } from 'next/router'
export async function getServerSideProps({ req }) { function RouterComp(props) {
const router = useRouter()
if (!router) {
throw new Error('router is missing!')
}
return (
<>
<p>props {JSON.stringify(props)}</p>
<p>router: {JSON.stringify(router)}</p>
</>
)
}
export async function getServerSideProps({ req, query, preview }) {
// this ensures the same router context is used by the useRouter hook
// no matter where it is imported
console.log(
ReactDOM.renderToString(
<RouterContext.Provider
value={{
query,
pathname: '/',
asPath: req.url,
isPreview: preview,
}}
>
<p>hello world</p>
<RouterComp hello={'world'} />
</RouterContext.Provider>
)
)
return { return {
props: { props: {
url: req.url, url: req.url,
......
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