Global CSS cannot be imported from within node_modules.

See original GitHub issue

Hi!

Thanks for trying to contibute to solving the Next 10 / Webpack 5 / Ant Design mess 😉

I am trying you solution, but ending up with

info  - Creating an optimized production build  
Failed to compile.

./node_modules/antd/lib/affix/style/index.less
Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: node_modules/antd/lib/affix/style/index.js
...
Error: > Build failed because of webpack errors

This does not happen if I try to add the <Affix/> component to your example code. I cannot quite figure what the difference is though. Any tips?

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
akornatocommented, May 4, 2021

@JesperWe removing .babelrc that I had from Next.js example fixed this for me.

1reaction
jaywcjlovecommented, May 28, 2021

I created a nextjs package next-remove-imports to solve the problem.

Example: https://codesandbox.io/s/nextjs-example-react-md-editor-qjhn7?file=/pages/index.js

// next.config.js
const removeImports = require("next-remove-imports")();

module.exports = removeImports({});
// pages/index.js

import Head from 'next/head'
import MDEditor from '@uiw/react-md-editor';
import "@uiw/react-md-editor/dist/markdown-editor.css";
import "@uiw/react-markdown-preview/dist/markdown.css";

export default function Home() {
  return (
    <div>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <MDEditor value="**Hello world!!!**" />
    </div>
  )
}

@JesperWe

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global CSS cannot be imported from within node_modules.
Main reasons behind this are that we don't compile node_modules further, meaning those files can't be found during pre-rendering and would crash ...
Read more >
Next.js Global CSS cannot be imported from files other than ...
Hey, I created and move the main. · @IndustryDesigns, try to use node-sass instead of @zeit/next-sass , I just tested it and updated...
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 >
Global CSS cannot be imported from within node_modules
18 Day 11 77. Combinations Given two integers n and k, return all possible combinations of k numbers out of the range [1,...
Read more >
Next.js Global CSS cannot be imported from files other than ...
CSS : Next.js Global CSS cannot be imported from files other than your Custom App [ Beautify Your Computer ...
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