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.

[@next/storybook] - incorrectly imported css throws an inaccurate error

See original GitHub issue

Bug report

Describe the bug

When a css file is imported in the wrong way, rather than displaying an error that describes the problem, the error can't resolve 'error-loader' is displayed, with no stack trace.

To Reproduce

  1. I made this repo for use with duplication
  2. Add a normal .css file and import it within one of the stories (this is not allowed, since normal css imports are only possible in _app.js)
  3. Observe the incorrect error message

Expected behavior

I would expect that the error message mirror that which you receive when using next.js normally - something along the lines of “global css imports are not allowed within pages, please use a css module or import within _app.js”

System information

  • OS: macOS
  • Version of Next.js: 9.4.4
  • Version of Node.js: 12.13.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jnvcommented, Aug 21, 2020

Okay, I have managed to make it work with global CSS by injecting a custom set of rules into that oneOf array, so it kinda work without rewriting all the CSS / CSS modules rules. I use the following Storybook config on top of the Next’s SB plugin (note that this is Sass-specific but you can easily make it will work with CSS only):

// .storybook/main.js
const {sassOptions} = require('../next.config')
const path = require('path')

const includePath = path.resolve(__dirname, '../')

const cssRules = [
  {
    sideEffects: true,
    test: /(?<!\.module)\.css$/,
    use: ['style-loader', 'css-loader'],
    include: includePath,
  },
  {
    sideEffects: true,
    test: /(?<!\.module)\.(scss|sass)$/,
    use: [
      'style-loader',
      'css-loader',
      {
        loader: 'sass-loader',
        options: {
          sourceMap: true,
          sassOptions,
        },
      },
    ],
    include: includePath,
  },
]

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: [
    '@next/plugin-storybook',
    '@storybook/addon-links',
    '@storybook/addon-essentials',
  ],
  webpackFinal: async (config) => {
    const oneOfRule = config.module.rules.find((rule) => !!rule.oneOf)
    oneOfRule.oneOf = [...cssRules, ...oneOfRule.oneOf]
    return config
  },
}
0reactions
github-actions[bot]commented, Dec 1, 2022

Please verify that your issue can be recreated with next@canary.

Why was this issue marked with the please verify canary label?

We noticed the provided reproduction was using an older version of Next.js, instead of canary.

The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. You can think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running npm install next@canary and test it in your project, using your reproduction steps.

If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.

How can I quickly verify if my issue has been fixed in canary?

The safest way is to install next@canary in your project and test it, but you can also search through closed Next.js issues for duplicates or check the Next.js releases.

My issue has been open for a long time, why do I need to verify canary now?

Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.

What happens if I don’t verify against the canary version of Next.js?

An issue with the please verify canary that receives no meaningful activity (e.g. new comments that acknowledge verification against canary) will be automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using next@canary.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment “I have the same issue” without repro steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren’t you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

Read more comments on GitHub >

github_iconTop Results From Across the Web

[@next/storybook] - incorrectly imported css throws an ...
When a css file is imported in the wrong way, rather than displaying an error that describes the problem, the error can't resolve...
Read more >
Import Global CSS file inside _app.js in next js throws error ...
So, I tried to import some global style in the _app.js component. But when I build the code, I get the following error....
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
Features | Vite
The above will throw an error in the browser. Vite will detect such bare module imports in all served source files and perform...
Read more >
Customer Engagement – AWS Contact Center - Amazon AWS
Once this contact flow is imported, you can save and publish it making use of ... in event) # Check for any errors...
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