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

coreCss not importing correctly #100

Closed
thrberglund opened this issue Jun 26, 2024 · 4 comments
Closed

coreCss not importing correctly #100

thrberglund opened this issue Jun 26, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@thrberglund
Copy link

thrberglund commented Jun 26, 2024

EDIT: sorry, looks like I simply had to enable css modules and everything worked despite using a really old version of css-loader. Please resolve or delete this issue if it's expected that I need to add css-module handling to my config.

When importing the ColorPicker I get the following error:
image

Google seemed to indicate that it might be an issue with using old css-loader version, see: facebook/create-react-app#11800

With that in mind, I tried hacking index.js and added the old syntax, ie

import * as coreCss from '../core.module.css';
//import coreCss from '../core.module.css';

With those changes, it now built without any errors.

Does this indicate that you are missing a dependency for css-loader?

Apologies if I'm missing something and this issue is on my side.

@thrberglund thrberglund changed the title coreCss not importing correctly (missing css-loader dependency?) coreCss not importing correctly Jun 26, 2024
@hxf31891 hxf31891 self-assigned this Jun 26, 2024
@hxf31891
Copy link
Owner

@thrberglund I will check this out now, CSS has long been an issue with this project.

Can you give me some info on your env? Are you using Next or Vite?

@hxf31891 hxf31891 added the bug Something isn't working label Jun 26, 2024
@thrberglund
Copy link
Author

thrberglund commented Jun 26, 2024

@hxf31891
We are using webpack. The relevant code in our webpack config file looked something like this:

module: {
    rules: [
        {
            test: /\.css$/,
            use: ['style-loader', 'css-loader'],
        },
    ],
},

The solution was to enable modules, so at first I did this:

module: {
    rules: [
        {
            test: /\.css$/,
            use: [
               'style-loader'
                {
                    loader: 'css-loader',
                    options: {
                        modules: true,
                    },
                },
            ],
        },
    ],
},

HOWEVER, while it fixed the color picker, this now caused issues with importing normal css files. So the final version (hopefully) now handles .css and .module.css differently.

module: {
    rules: [
        {
            test: /\.module\.css$/,
            use: [
                 'style-loader',
                {
                    loader: 'css-loader',
                    options: {
                        modules: true,
                    },
                },
            ],
        },
        {
            test: /^((?!\.module).)*\.css$/,
            use: [ 'style-loader', 'css-loader'],
        },
    ],
},

This seems to work so far. That said, I don't feel like I should have to make all these changes just to use a color picker package, so if you are able to fix it up then that would be great :)

EDIT: for anyone that miught stumble across my post when researching an issue, here's a better way of writing the non-module rules:

test: /\.css$/,
exclude: /\.module\.css$/,

@thrberglund
Copy link
Author

thrberglund commented Jul 2, 2024

I thought my fix above was enough, but after trying to use it, I'm getting several other issues. Other webpack builds are failing with the same issue, the vite tests fail with "unknown file extension", storybook was initially failing with the same module has no export and when I tried to fix it, it's now saying that the module build failed due to missing semicolon etc.

All the issues are related to this module.core.css file though and it's essentially just different varieties of the same issue.

I'm trying to understand and fix up all the configs to get this thing finally fully working, but it's very frustrating and I've never had any similar issue with the multitude of other packages we are using. If it's possible to rewrite your handling to not have all these dependencies, then that would be amazing. I'm just about ready to throw my hands in the air and write my own custom color picker instead. Which is a shame, because I quite like it.

EDIT: I think I've managed to fix the various configs. Fingers crossed.

@hxf31891
Copy link
Owner

@thrberglund this should be fixed as of 3.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants