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
0faedd9e
Unverified
Commit
0faedd9e
authored
Jan 19, 2023
by
Hannes Bornö
Committed by
GitHub
Jan 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error when CSS @import fails to resolve (#45010)
parent
0a5097c4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
27 deletions
+95
-27
parseNotFoundError.ts
...ack/plugins/wellknown-errors-plugin/parseNotFoundError.ts
+49
-25
ReactRefreshLogBox.test.ts
test/development/acceptance-app/ReactRefreshLogBox.test.ts
+32
-0
ReactRefreshLogBox.test.ts.snap
...eptance-app/__snapshots__/ReactRefreshLogBox.test.ts.snap
+10
-0
index.test.js
test/integration/jsconfig-baseurl/test/index.test.js
+2
-1
index.test.js
test/integration/jsconfig-paths/test/index.test.js
+2
-1
No files found.
packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts
View file @
0faedd9e
...
@@ -45,21 +45,17 @@ function getModuleTrace(input: any, compilation: any) {
...
@@ -45,21 +45,17 @@ function getModuleTrace(input: any, compilation: any) {
return
moduleTrace
return
moduleTrace
}
}
export
async
function
getNotFoundError
(
async
function
getSourceFrame
(
compilation
:
webpack
.
Compilation
,
input
:
any
,
input
:
any
,
fileName
:
string
fileName
:
any
,
)
{
compilation
:
any
if
(
input
.
name
!==
'ModuleNotFoundError'
)
{
):
Promise
<
{
frame
:
string
;
lineNumber
:
string
;
column
:
string
}
>
{
return
false
try
{
}
const
loc
=
input
.
loc
const
loc
=
input
.
loc
?
input
.
loc
?
input
.
loc
:
input
.
dependencies
.
map
((
d
:
any
)
=>
d
.
loc
).
filter
(
Boolean
)[
0
]
:
input
.
dependencies
.
map
((
d
:
any
)
=>
d
.
loc
).
filter
(
Boolean
)[
0
]
const
originalSource
=
input
.
module
.
originalSource
()
const
originalSource
=
input
.
module
.
originalSource
()
try
{
const
result
=
await
createOriginalStackFrame
({
const
result
=
await
createOriginalStackFrame
({
line
:
loc
.
start
.
line
,
line
:
loc
.
start
.
line
,
column
:
loc
.
start
.
column
,
column
:
loc
.
start
.
column
,
...
@@ -69,11 +65,38 @@ export async function getNotFoundError(
...
@@ -69,11 +65,38 @@ export async function getNotFoundError(
frame
:
{},
frame
:
{},
})
})
// If we could not result the original location we still need to show the existing error
return
{
if
(
!
result
)
{
frame
:
result
?.
originalCodeFrame
??
''
,
return
input
lineNumber
:
result
?.
originalStackFrame
?.
lineNumber
?.
toString
()
??
''
,
column
:
result
?.
originalStackFrame
?.
column
?.
toString
()
??
''
,
}
}
catch
{
return
{
frame
:
''
,
lineNumber
:
''
,
column
:
''
}
}
}
export
async
function
getNotFoundError
(
compilation
:
webpack
.
Compilation
,
input
:
any
,
fileName
:
string
)
{
if
(
input
.
name
!==
'ModuleNotFoundError'
&&
!
(
input
.
name
===
'ModuleBuildError'
&&
/Error: Can't resolve '.+' in /
.
test
(
input
.
message
)
)
)
{
return
false
}
}
try
{
const
{
frame
,
lineNumber
,
column
}
=
await
getSourceFrame
(
input
,
fileName
,
compilation
)
const
errorMessage
=
input
.
error
.
message
const
errorMessage
=
input
.
error
.
message
.
replace
(
/ in '.*
?
'/
,
''
)
.
replace
(
/ in '.*
?
'/
,
''
)
.
replace
(
/Can't resolve '
(
.*
)
'/
,
`Can't resolve '
${
chalk
.
green
(
'$1'
)}
'`
)
.
replace
(
/Can't resolve '
(
.*
)
'/
,
`Can't resolve '
${
chalk
.
green
(
'$1'
)}
'`
)
...
@@ -88,7 +111,8 @@ export async function getNotFoundError(
...
@@ -88,7 +111,8 @@ export async function getNotFoundError(
name
&&
name
&&
!
/next-
(
app|middleware|client-pages|flight-
(
client|server|client-entry
))
-loader
\.
js/
.
test
(
!
/next-
(
app|middleware|client-pages|flight-
(
client|server|client-entry
))
-loader
\.
js/
.
test
(
name
name
)
)
&&
!
/css-loader.+
\.
js/
.
test
(
name
)
)
)
if
(
moduleTrace
.
length
===
0
)
return
''
if
(
moduleTrace
.
length
===
0
)
return
''
...
@@ -97,8 +121,6 @@ export async function getNotFoundError(
...
@@ -97,8 +121,6 @@ export async function getNotFoundError(
)}
\n\n`
)}
\n\n`
}
}
const
frame
=
result
.
originalCodeFrame
??
''
let
message
=
let
message
=
chalk
.
red
.
bold
(
'Module not found'
)
+
chalk
.
red
.
bold
(
'Module not found'
)
+
`:
${
errorMessage
}
`
+
`:
${
errorMessage
}
`
+
...
@@ -108,12 +130,14 @@ export async function getNotFoundError(
...
@@ -108,12 +130,14 @@ export async function getNotFoundError(
importTrace
()
+
importTrace
()
+
'
\
nhttps://nextjs.org/docs/messages/module-not-found'
'
\
nhttps://nextjs.org/docs/messages/module-not-found'
return
new
SimpleWebpackError
(
let
formattedFileName
:
string
=
chalk
.
cyan
(
fileName
)
`
${
chalk
.
cyan
(
fileName
)}
:
${
chalk
.
yellow
(
if
(
lineNumber
&&
column
)
{
result
.
originalStackFrame
.
lineNumber
?.
toString
()
??
''
formattedFileName
+=
`:
${
chalk
.
yellow
(
lineNumber
)}
:
${
chalk
.
yellow
(
)}:
$
{
chalk
.
yellow
(
result
.
originalStackFrame
.
column
?.
toString
()
??
''
)}
`,
column
message
)}
`
)
}
return
new
SimpleWebpackError
(
formattedFileName
,
message
)
}
catch
(
err
)
{
}
catch
(
err
)
{
// Don't fail on failure to resolve sourcemaps
// Don't fail on failure to resolve sourcemaps
return
input
return
input
...
...
test/development/acceptance-app/ReactRefreshLogBox.test.ts
View file @
0faedd9e
...
@@ -1375,5 +1375,37 @@ for (const variant of ['default', 'turbo']) {
...
@@ -1375,5 +1375,37 @@ for (const variant of ['default', 'turbo']) {
await
cleanup
()
await
cleanup
()
})
})
test
(
"Can't resolve @import in CSS file"
,
async
()
=>
{
const
{
session
,
cleanup
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/styles1.css'
,
'@import "./styles2.css"'
],
[
'app/styles2.css'
,
'@import "./boom.css"'
],
])
)
await
session
.
patch
(
'app/layout.js'
,
`
import "./styles1.css"
export default function RootLayout({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
`
)
expect
(
await
session
.
hasRedbox
(
true
)).
toBe
(
true
)
expect
(
await
session
.
getRedboxSource
()).
toMatchSnapshot
()
await
cleanup
()
})
})
})
}
}
test/development/acceptance-app/__snapshots__/ReactRefreshLogBox.test.ts.snap
View file @
0faedd9e
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ReactRefreshLogBox app default Can't resolve @import in CSS file 1`] = `
"./app/styles2.css
Module not found: Can't resolve './boom.css'
Import trace for requested module:
./app/styles1.css
https://nextjs.org/docs/messages/module-not-found"
`;
exports[`ReactRefreshLogBox app default Import trace when module not found in layout 1`] = `
exports[`ReactRefreshLogBox app default Import trace when module not found in layout 1`] = `
"./app/module.js:1:0
"./app/module.js:1:0
Module not found: Can't resolve 'non-existing-module'
Module not found: Can't resolve 'non-existing-module'
...
...
test/integration/jsconfig-baseurl/test/index.test.js
View file @
0faedd9e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
{
import
{
renderViaHTTP
,
renderViaHTTP
,
findPort
,
findPort
,
...
@@ -54,7 +55,7 @@ describe('TypeScript Features', () => {
...
@@ -54,7 +55,7 @@ describe('TypeScript Features', () => {
await
renderViaHTTP
(
appPort
,
'/hello'
)
await
renderViaHTTP
(
appPort
,
'/hello'
)
const
found
=
await
check
(
const
found
=
await
check
(
()
=>
output
,
()
=>
stripAnsi
(
output
)
,
/Module not found: Can't resolve 'components
\/
worldd'/
,
/Module not found: Can't resolve 'components
\/
worldd'/
,
false
false
)
)
...
...
test/integration/jsconfig-paths/test/index.test.js
View file @
0faedd9e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
import
stripAnsi
from
'next/dist/compiled/strip-ansi'
import
*
as
path
from
'path'
import
*
as
path
from
'path'
import
{
import
{
renderViaHTTP
,
renderViaHTTP
,
...
@@ -74,7 +75,7 @@ function runTests() {
...
@@ -74,7 +75,7 @@ function runTests() {
await
renderViaHTTP
(
appPort
,
'/basic-alias'
)
await
renderViaHTTP
(
appPort
,
'/basic-alias'
)
const
found
=
await
check
(
const
found
=
await
check
(
()
=>
output
,
()
=>
stripAnsi
(
output
)
,
/Module not found: Can't resolve '@c
\/
worldd'/
,
/Module not found: Can't resolve '@c
\/
worldd'/
,
false
false
)
)
...
...
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