purifycss-webpack icon indicating copy to clipboard operation
purifycss-webpack copied to clipboard

css.charAt is not a function

Open slovyagin opened this issue 8 years ago • 16 comments

I have such error when trying to use the plugin.

Here’s how I’ve set up the CSS loaders:

      {
        test: /\.styl$/,
        include: paths.appSrc,
        exclude: paths.appComponents,
        loader: ExtractTextPlugin.extract(
          ['style'],
          [
            'css?importLoaders=1',
            'postcss',
            'stylus'
          ]
        )
      },
      {
        test: /\.styl$/,
        include: paths.appComponents,
        loader: ExtractTextPlugin.extract(
          ['style'],
          [
            'css?modules&importLoaders=1&localIdentName=[folder]__[local]___[hash:base64:5]',
            'postcss',
            'stylus',
          ]),
      },
      {
        test: /\.(woff|woff2).css$/,
        include: paths.appSrc,
        loader: 'file',
        query: {
          name: 'static/css/[name].[ext]'
        }
      }

First and second are for processing Stylus styles and CSS modules, the third is just to move CSS containing base64 encoded WOFF(2) fonts into build dir.

Here’s the setup of ExtractTextPlugin:

new ExtractTextPlugin('static/css/[name].[contenthash:8].css')

And finally the PurifyPlugin:

    new PurifyPlugin({
      // Give paths to parse for rules. These should be absolute!
      paths: glob.sync(`${paths.appSrc}/*`),
      extensions: ['.html', '.jsx'],
      purifyOptions: {
        info: true,
        rejected: true
      }
    })

I’ve tried a lot of ways to specify the paths, like in README, like in examples, by absolute paths (/User/…), but no luck.

I’ve updated the plugin and Webpack, but it also doesn’t help.

Any help and ideas about what could go wrong?

slovyagin avatar Jan 19 '17 19:01 slovyagin

Are you using the Git version? I haven't published it to npm yet (problems with npm, I have to rename the package etc.). Can you set up a standalone example?

bebraw avatar Jan 19 '17 19:01 bebraw

Sorry, I didn’t understand you. I've installed the package from npm and tried the version from Github, but the result is the same. But I don't see any sense in it, because they have the same version 2.0.3. I'll try to provide a small example to reproduce this behaviour.

slovyagin avatar Jan 19 '17 21:01 slovyagin

The GitHub version has some serious improvements in it. The API is completely different than in the npm one, though. Your code will fail if you run it against the npm version with your config above.

This is why I asked for a standalone example (mentioned in the issue template too!).

bebraw avatar Jan 19 '17 21:01 bebraw

mentioned in the issue template too! 🤷

Anyway the bug is still here, I will send you a sample to reproduce it

slovyagin avatar Jan 20 '17 08:01 slovyagin

Ah, it's not so easy to reproduce this behaviour at a small sample, need some time for that

slovyagin avatar Jan 23 '17 08:01 slovyagin

@crvst No probs. I'll rename this plugin today and do some maintenance. Time to get a version out there.

bebraw avatar Jan 23 '17 08:01 bebraw

Hi,

I published the new version. Please adapt your setup to that and see if that helps. I added verbose flag that should help in debugging.

bebraw avatar Jan 23 '17 10:01 bebraw

Sadly, the update didn't help. The process likely even doesn't reach that verbose log part. All I see is a node error stack trace.

TypeError: css.charAt is not a function
    at comment ([...]/node_modules/css/lib/parse/index.js:168:20)

And so on.

I forgot to add that using cli tool directly works well and eliminates styles properly and without any complications.

I'd ask you not close the issue for now, please, I'll try to investigate it and post some results later.

slovyagin avatar Jan 24 '17 07:01 slovyagin

If you can set up a small repository showcasing the issue, I don't mind digging into it.

Can you see why/where css package is used? I haven't seen that on webpack projects before.

bebraw avatar Jan 24 '17 08:01 bebraw

Is there a quick way to know what dependecy relies on it?

slovyagin avatar Jan 24 '17 08:01 slovyagin

npm ls I think.

bebraw avatar Jan 24 '17 08:01 bebraw

One option is that you have something like loaders: ['css', ...] somewhere in your configuration. That will pick up css over css-loader if you have both installed. I would rewrite loader definitions with -loader suffix anyway.

bebraw avatar Jan 24 '17 08:01 bebraw

Well, umm, the only place where css is used the plugin, hope I understand you right.

└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └── [email protected]

slovyagin avatar Jan 24 '17 08:01 slovyagin

Ah, I see. It chokes at purify-css then. I would need a project to fix this unless you feel like digging in. 👍

bebraw avatar Jan 24 '17 08:01 bebraw

OK, thanks, I need some time to reproduce it at a small project!

slovyagin avatar Jan 24 '17 08:01 slovyagin

Alright. It's weird verbose: true doesn't show anything as purify is triggered after that. But I'll know more once I have some code to study.

bebraw avatar Jan 24 '17 08:01 bebraw