question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing Global CSS in Next.js with Webpack

See original GitHub issue

Current 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:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
leerobcommented, Aug 18, 2021

We are going to allow global CSS imports 👍

https://github.com/vercel/next.js/discussions/27953

3reactions
JessicaSachscommented, Aug 18, 2021

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found