Importing Global CSS in Next.js with Webpack
See original GitHub issueCurrent behavior
Following this migration guide, it is recommended to add (global) stylesheets to your tests. Nextjs’s webpack wouldn’t allow you to add them to your components anyway. But, when you add styles to a test, all tests (in cypress open-ct
) hang on Your tests are loading...
.
import 'tailwindcss/tailwind.css' // or '../styles/index.css'
import { mount } from '@cypress/react'
import Button from '.'
describe('<Button />', () => {
it('should mount', () => {
mount(<Button />)
cy.contains('click me')
})
})
Desired behavior
For the global styles to get applied.
Test code to reproduce
// cypress/plugins/index.ts
const injectNextDevServer = require('@cypress/react/plugins/next')
const pluginConfig: Cypress.PluginConfig = (on, config) => {
if (config.testingType === 'component') {
injectNextDevServer(on, config)
}
return config
}
module.exports = pluginConfig
Versions
Cypress package version: 7.5.0
Cypress binary version: 7.5.0
Electron version: 12.0.0-beta.14
Bundled Node version: 14.15.1
OS: (Linux) 5.10.36-2-MANJARO
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Basic Features: Built-in CSS Support - Next.js
Next.js allows you to import CSS files from a JavaScript file. This is possible because Next.js extends the concept of import beyond JavaScript....
Read more >Next.js: Global CSS cannot be imported from files other than ...
When migrating to Next.js 9+, I was running into an issue where I could not import global styles from any file other than...
Read more >Next.js Global CSS cannot be imported from files other than ...
Since Next.js 9.2 global CSS must be imported in Custom <App> component. // pages/_app.js import '../global-styles/main.scss' export default ...
Read more >Global vs. Local Styling In Next.js - Smashing Magazine
Another advantage to CSS modules is performance. Next.js includes a dynamic import feature. next/dynamic lets us lazy load components so that ...
Read more >global css cannot be imported from within node_modules ...
Since Next.js 9.5.4, importing a CSS file from node_modules is permitted anywhere in your application. For global stylesheets, like bootstrap or nprogress, you ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are going to allow global CSS imports 👍
https://github.com/vercel/next.js/discussions/27953
We’re working on designing the API for global CSS imports right now. It seems like Next.js can be pretty restrictive when it comes to supporting developer tools/non-Next.js environments. (Storybook has these problems, too).
If you folks (@natterstefan or @smhmd) have any ideas for how to solve this going forward, we’d like some input 😃