Unverified Commit c9d9ff6a authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Informative Error for Invalid Global CSS (#8958)

* Informative Error for Invalid Global CSS
This adds a helpful error message with a (basic) err.sh link for invalid Global CSS usage.

We'll want to expand on this topic more and offer alternatives when CSS Modules support lands.

* Update expected error message
parent d299811b
# Global CSS Must Be in Your Custom <App>
#### Why This Error Occurred
An attempt to import Global CSS from a file other than `pages/_app.js` was made.
Global CSS cannot be used in files other than your Custom `<App>` due to its side-effects and ordering problems.
#### Possible Ways to Fix It
Relocate all Global CSS imports to your `pages/_app.js` file.
This diff is collapsed.
import loaderUtils from 'loader-utils'
import { loader } from 'webpack'
const ErrorLoader: loader.Loader = function() {
const options = loaderUtils.getOptions(this) || {}
const { reason = 'An unknown error has occurred' } = options
const err = new Error(reason)
this.emitError(err)
}
export default ErrorLoader
...@@ -194,7 +194,7 @@ describe('CSS Support', () => { ...@@ -194,7 +194,7 @@ describe('CSS Support', () => {
}) })
expect(stderr).toContain('Failed to compile') expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.css') expect(stderr).toContain('styles/global.css')
expect(stderr).toContain('no loaders are configured to process this file') expect(stderr).toContain('Please move all global CSS imports')
}) })
}) })
...@@ -211,7 +211,7 @@ describe('CSS Support', () => { ...@@ -211,7 +211,7 @@ describe('CSS Support', () => {
}) })
expect(stderr).toContain('Failed to compile') expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.css') expect(stderr).toContain('styles/global.css')
expect(stderr).toContain('no loaders are configured to process this file') expect(stderr).toContain('Please move all global CSS imports')
}) })
}) })
...@@ -228,7 +228,7 @@ describe('CSS Support', () => { ...@@ -228,7 +228,7 @@ describe('CSS Support', () => {
}) })
expect(stderr).toContain('Failed to compile') expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('styles/global.css') expect(stderr).toContain('styles/global.css')
expect(stderr).toContain('no loaders are configured to process this file') expect(stderr).toContain('Please move all global CSS imports')
}) })
}) })
......
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