Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global CSS cannot be imported from within node_modules (next js) #6

Closed
junjou opened this issue Aug 6, 2021 · 13 comments
Closed

Global CSS cannot be imported from within node_modules (next js) #6

junjou opened this issue Aug 6, 2021 · 13 comments

Comments

@junjou
Copy link

junjou commented Aug 6, 2021

Hello,

Seems like it can't work with nextjs:

image

@akursat
Copy link
Owner

akursat commented Sep 2, 2021

@junjou The maintainers of nextjs planning to allow CSS imports from node_modules. I hope the error will be gone. I'll follow the PR and test it when it is merged.
vercel/next.js#19936
vercel/next.js#27953

@koeit
Copy link

koeit commented May 28, 2022

Is this still not fixed @akursat or any workaround?

@akursat
Copy link
Owner

akursat commented Jun 14, 2022

@koeit Please follow the discussion vercel/next.js#27953 possible workaround

@bsor-dev
Copy link

bsor-dev commented Aug 22, 2022

+1
@akursat your plugin is outdated maybe you could help other future users by updating it

image

@SublimeProphets
Copy link

upvote! :-)

@vehere-ccuMaksym
Copy link

Does anyone found some solution? Can you share the code if "yes"?

@r1skz3ro
Copy link

@StrangersSoftware use this library - https://github.com/bem/next-global-css

adjust your next.config.js like in the snippet below, restart the project and it should work :)

  const { patchWebpackConfig } = require('next-global-css');
  const webpackNodeExternals = require('webpack-node-externals');
  
  const nextConfig = {
    {...}
    webpack: (config, options) => {
      patchWebpackConfig(config, options);
      if (options.isServer) {
        config.externals = webpackNodeExternals({
          allowlist: [/design-system/],
        });
      }
      return config;
    },
    {...}
  };

@akursat
Copy link
Owner

akursat commented Dec 28, 2022

@junjou @r1skz3ro @StrangersSoftware @SublimeProphets @bsor-dev @koeit The addressed problem should be gone with the new version. Please give it a try and let me know if you still encounter a problem.

@akursat akursat closed this as completed Dec 28, 2022
@StrangerTwo
Copy link

StrangerTwo commented Dec 31, 2022

@akursat Currently using the version 2.1.0 and still facing this issue.

error - ../node_modules/react-leaflet-cluster/lib/assets/MarkerCluster.Default.css
Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: ../node_modules/react-leaflet-cluster/lib/index.js

Let me know if I can help you provide any other information.

@StrangerTwo
Copy link

I believe the file https://github.com/akursat/react-leaflet-cluster/blob/main/src/index.tsx should not import

import 'leaflet.markercluster/dist/MarkerCluster.css'
import 'leaflet.markercluster/dist/MarkerCluster.Default.css

nor

import './assets/MarkerCluster.css'
import './assets/MarkerCluster.Default.css'

And instead the documentation of 'react-leaflet-cluster' should be changed, so that people import these css files themselves.

Let me know your thoughts! Thanks

StrangerTwo added a commit to StrangerTwo/react-leaflet-cluster that referenced this issue Dec 31, 2022
@vehere-ccuMaksym
Copy link

@junjou @r1skz3ro @StrangersSoftware @SublimeProphets @bsor-dev @koeit The addressed problem should be gone with the new version. Please give it a try and let me know if you still encounter a problem.

The new version still gives me the same error on Next.js.

I solved this by using your index.tsx file as one of my components and added all styles in my projects global css-file.
All the necessary dependencies respectively too.

Thanks for your plugin!

@jackbuscombe
Copy link

Add this to the next.config.js file:
transpilePackages: ["react-leaflet-cluster"],

@jakobskrym
Copy link

Add this to the next.config.js file: transpilePackages: ["react-leaflet-cluster"],

This worked for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants