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

Next.js error: Global CSS cannot be imported from within node_modules. #42

Closed
danforejtek opened this issue May 27, 2021 · 4 comments
Closed

Comments

@danforejtek
Copy link

I am using Next.js 10.2.0 and when I use SegmentedControlWithoutStyles this error appears

error - ./node_modules/segmented-control/dist/SegmentedControl.css
Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: node_modules/segmented-control/dist/SegmentedControl.js
@lorensr
Copy link
Owner

lorensr commented May 27, 2021

What's the import statement look like? The exported SegmentedControlWithoutStyles file doesn't import .css:

https://github.com/lorensr/segmented-control/blob/master/src/SegmentedControlWithoutStyles.js

Vs SegmentedControl, which does:

https://github.com/lorensr/segmented-control/blob/master/src/SegmentedControl.js

@jaywcjlove
Copy link

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

@danforejtek :)

@danforejtek
Copy link
Author

Imported like this:

import { SegmentedControlWithoutStyles } from 'segmented-control'

Used same as example in readme:

<SegmentedControlWithoutStyles
  name="oneDisabled"
  options={[
    { label: "One", value: "one", disabled: true },
    { label: "Two", value: "two" },
    { label: "Three", value: "three", default: true },
    { label: "Four", value: "four" }
  ]}
  setValue={newValue => this.doSomething(newValue)}
  style={{ width: 400, color: '#ab47bc' }} // purple400
/>

@lorensr
Copy link
Owner

lorensr commented May 28, 2021

Thanks! I fixed this in 0.1.17. Use this import:

import SegmentedControlWithoutStyles from 'segmented-control/SegmentedControlWithoutStyles'

@lorensr lorensr closed this as completed May 28, 2021
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

3 participants