Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5e92ae01
Unverified
Commit
5e92ae01
authored
May 28, 2021
by
JJ Kasper
Committed by
GitHub
May 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix external check for non-local next import (#25518)
parent
39181c40
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+9
-0
index.js
test/integration/getserversideprops/pages/index.js
+36
-1
No files found.
packages/next/build/webpack-config.ts
View file @
5e92ae01
...
@@ -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
[/\\]
/
)
||
...
...
test/integration/getserversideprops/pages/index.js
View file @
5e92ae01
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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment