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.

Cannot import CSS from node_modules in Next.js 10.2.0

See original GitHub issue

Reduced Test Case

You must paste a link to a REDUCED TEST CASE. If you do not, this issue will automatically be closed. To prevent this, include the text “not reproducible with a link” (assuming it’s true).

https://codesandbox.io/s/elastic-kilby-jdlql

Bug Description

Currently, I am using the solution provided for Next.js, using next-transpile-module and babel-plugin-transform-require-ignore. https://github.com/fullcalendar/fullcalendar-example-projects/tree/master/next-scheduler.

I’ve been using nextjs with version 10.1.3 and with a few modifications I was able to make it work. But with the release of Next.js 10.2.0 - https://nextjs.org/blog/next-10-2. I am getting the same old error. (That I cannot import CSS from node_modules).

What do you expect to happen? The application runs correctly.

What happens instead? Build throws an error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
pshdev1030commented, Jan 13, 2022

this article will help you

0reactions
spencerwmilescommented, Aug 2, 2022

I know this is a closed thread, but thought I’d chime in with my own experience and help others who may also run into this issue.

I use Tailwind for my CSS needs, so your mileage may vary depending on what your use cases are.

Using the exposed webpack config in next.config.js, I was able to just “stub out” the CSS imports entirely. Doing this was kind of a 2-for-1, I was able to reduce my CSS being shipped to the client by >50% + there is no longer a requirement to transpile the library anymore.

This has given me a clean slate and the ability to implement any FC style how I see fit without having to fight overrides, etc.

/** @type {import('next').NextConfig} */ module.exports = { reactStrictMode: true, swcMinify: true, webpack: (config) => { // bit of a hack to get around fullcalendar trying to import stylesheets // we do not need them so this is a good method of stubbing them out // also prevents the need to transpile them config.resolve.alias["./main.css"] = false; return config; }, ...

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Built-in CSS Support - Next.js
In production, all CSS files will be automatically concatenated into a single minified .css file. Import styles from node_modules. Since Next.js 9.5 ...
Read more >
Import css from a file in shared module or node module in next js
Problem: I want to import a css file from a shared module to css files in the NextJS apps. For example, I want...
Read more >
less-loader - npm
The loader will first try to resolve @import as relative, if it cannot be resolved, the loader will try to resolve @import inside...
Read more >
How to Add Font in Next.js (12.0.1 Updated) | Nextjs - Medium
Next.js improves font optimization in the latest version and provides a disabled ... CSS provides in build @import property to add a font...
Read more >
sass-loader | Yarn - Package Manager
Why can you remove it? The loader will first try to resolve @import as a relative path. If it cannot be resolved, then...
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