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
14b18da0
Unverified
Commit
14b18da0
authored
Dec 27, 2019
by
Joe Haddad
Committed by
GitHub
Dec 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Special Global CSS Error within `node_modules` (#9849)
parent
5bd58d5a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
3 deletions
+67
-3
index.ts
packages/next/build/webpack/config/blocks/css/index.ts
+24
-2
messages.ts
packages/next/build/webpack/config/blocks/css/messages.ts
+8
-1
index.css
...ures/invalid-global-module/node_modules/example/index.css
+3
-0
index.js
...tures/invalid-global-module/node_modules/example/index.js
+1
-0
index.mjs
...ures/invalid-global-module/node_modules/example/index.mjs
+1
-0
package.json
...s/invalid-global-module/node_modules/example/package.json
+4
-0
index.js
...gration/css-fixtures/invalid-global-module/pages/index.js
+7
-0
index.test.js
test/integration/css-modules/test/index.test.js
+19
-0
No files found.
packages/next/build/webpack/config/blocks/css/index.ts
View file @
14b18da0
...
...
@@ -5,7 +5,11 @@ import MiniCssExtractPlugin from '../../../plugins/mini-css-extract-plugin'
import
{
loader
}
from
'../../helpers'
import
{
ConfigurationContext
,
ConfigurationFn
,
pipe
}
from
'../../utils'
import
{
getCssModuleLocalIdent
}
from
'./getCssModuleLocalIdent'
import
{
getGlobalImportError
,
getModuleImportError
}
from
'./messages'
import
{
getGlobalImportError
,
getGlobalModuleImportError
,
getLocalModuleImportError
,
}
from
'./messages'
import
{
getPostCssPlugins
}
from
'./plugins'
function
getClientStyleLoader
({
...
...
@@ -156,7 +160,7 @@ export const css = curry(async function css(
use
:
{
loader
:
'error-loader'
,
options
:
{
reason
:
getModuleImportError
(),
reason
:
get
Local
ModuleImportError
(),
},
},
},
...
...
@@ -210,6 +214,24 @@ export const css = curry(async function css(
)
}
// Throw an error for Global CSS used inside of `node_modules`
fns
.
push
(
loader
({
oneOf
:
[
{
test
:
/
\.
css$/
,
issuer
:
{
include
:
[
/node_modules/
]
},
use
:
{
loader
:
'error-loader'
,
options
:
{
reason
:
getGlobalModuleImportError
(),
},
},
},
],
})
)
// Throw an error for Global CSS used outside of our custom <App> file
fns
.
push
(
loader
({
...
...
packages/next/build/webpack/config/blocks/css/messages.ts
View file @
14b18da0
...
...
@@ -10,7 +10,14 @@ export function getGlobalImportError(file: string | null) {
)}
.\nRead more: https://err.sh/next.js/global-css`
}
export
function
getModuleImportError
()
{
export
function
getGlobalModuleImportError
()
{
// TODO: Read more link
return
`Global CSS
${
chalk
.
bold
(
'cannot'
)}
be imported from within
${
chalk
.
bold
(
'node_modules'
)}
.`
}
export
function
getLocalModuleImportError
()
{
// TODO: Read more link
return
`CSS Modules
${
chalk
.
bold
(
'cannot'
...
...
test/integration/css-fixtures/invalid-global-module/node_modules/example/index.css
0 → 100644
View file @
14b18da0
.redText
{
color
:
'red'
;
}
test/integration/css-fixtures/invalid-global-module/node_modules/example/index.js
0 → 100644
View file @
14b18da0
require
(
'./index.css'
)
test/integration/css-fixtures/invalid-global-module/node_modules/example/index.mjs
0 → 100644
View file @
14b18da0
import
'./index.css'
test/integration/css-fixtures/invalid-global-module/node_modules/example/package.json
0 → 100644
View file @
14b18da0
{
"name"
:
"example"
,
"main"
:
"index"
}
test/integration/css-fixtures/invalid-global-module/pages/index.js
0 → 100644
View file @
14b18da0
import
'example'
function
Home
()
{
return
<
div
>
This
should
fail
at
build
time
.
<
/div
>
}
export
default
Home
test/integration/css-modules/test/index.test.js
View file @
14b18da0
...
...
@@ -181,6 +181,25 @@ describe('Invalid CSS Module Usage in node_modules', () => {
})
})
describe
(
'Invalid CSS Module Usage in node_modules'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'invalid-global-module'
)
beforeAll
(
async
()
=>
{
await
remove
(
join
(
appDir
,
'.next'
))
})
it
(
'should fail to build'
,
async
()
=>
{
const
{
stderr
}
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
})
expect
(
stderr
).
toContain
(
'Failed to compile'
)
expect
(
stderr
).
toContain
(
'node_modules/example/index.css'
)
expect
(
stderr
).
toMatch
(
/Global CSS.*cannot.*be imported from within.*node_modules/
)
})
})
describe
(
'Valid CSS Module Usage from within node_modules'
,
()
=>
{
const
appDir
=
join
(
fixturesDir
,
'nm-module'
)
...
...
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