GithubHelp home page GithubHelp logo

Cannot read property... about gulp-postcss HOT 40 CLOSED

postcss avatar postcss commented on May 27, 2024
Cannot read property...

from gulp-postcss.

Comments (40)

waldemarfm avatar waldemarfm commented on May 27, 2024

Can confirm. Exactly the same errors with same package versions.

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

Hi @simbo and @waldemarfm, thanks for reporting this! Recent change was only PostCSS version bump.

It seems that the problem is due to version mistmach between PostCSS and plugins. I checked autoprefixer-core 4.0.2 and found that it depends on PostCSS ~3.0.7

cc @ai

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Yeap. Should we use peerDependencies in Autoprefixer and other plugins?

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

Yeah, seems to be the right way to solve this problem. I will make this change to gulp-postcss as well so users will have more control over which version of PostCSS to use.

from gulp-postcss.

ai avatar ai commented on May 27, 2024

@MoOx are you agree to add peerDependencies to all plugins? Also I add this recommendation to plugin developer How To (it is in progress right now).

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

gulp-postcss now lists postcss in peerDependencies.

from gulp-postcss.

sondr3 avatar sondr3 commented on May 27, 2024

Sorry to bother, but any idea when this will be finished? :)

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

peerDep will be deprecated, so not sure it's a good idea.
npm/npm#6565

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

The why you should not use dep is overthere npm/npm#5080

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

@MoOx any suggestions on how to prevent version mismatch?

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Don't know any magic method. I just too many undesired issues with peerDep too.

Developers should take care of that. When someone upgrade a tool with some plugins, this person should ensure all plugins have versions that work with the new version of the tool. IMO, it's that simple.

Each plugins might specify minimal version they require in their README.

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Note that all the plugins I published for example have tests with a specific postcss version (cf devDep). Developers can also take a look to that. Version in README seems a good idea tho.

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Maybe we can set some special flag to plugin with PostCSS AST version they required? I do not really like this idea, only as brainstorm.

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Like:

module.export = {
    postcss: function () {},
    ast: '4.0.0'
}

And PostCSS will throw error if plugins expect different AST versions.

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Maybe more

module.export = {
    postcss: function () {},
    postcssVersion: require("./package.json").devDependencies.postcss
}

?

Note sure we should handle this in the core tho.
We all get this kind of issue with all tool/plugins things, this is not likely easy to solve.

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

If each plugin exposed its postcss version from package.json, then postcss itself could check it with smth like https://github.com/npm/node-semver and throw an error

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Main problems:

  1. Does API check is a part of PostCSS?
  2. What we will suggest to user? Downgrade plugin version?
  3. I think short plugin syntax (just a function) is important on debug. Should we allow it and miss API check it this case?

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

This suggestion seems to be the way how this should be solved npm/npm#5080 (comment)

from gulp-postcss.

yisibl avatar yisibl commented on May 27, 2024

It is certainly a headache problem.

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

I like the way isaac explains. So this can be handled in plugin like this:

var plugin = function () {}

plugin.supportedVersion = require("./package.json").dependencies.postcss || require("./package.json").devDependencies.postcss

module.export = plugin

It would be could to directly add a supportedVersion property to the plugin itself.
This way, postcss can check for this without having to rely on a object that contains function+supported version.

What do you think guys?

Btw, this should only show a warning because for example a plugin done for v3 can totally work for v4 (the otherwise is not likely to work all the time).

from gulp-postcss.

ai avatar ai commented on May 27, 2024

I found the best solution. We dont necessarily have to use one AST version in every plugin. If plugin uses old AST we can stringify current one and then reparse it with old PostCSS for this plugin.

Every plugin should have own PostCSS version in dependencies and will use special mathod to wrap plugin function:

var postcss = require('postcss');

module.exports = postcss.plugin(function (css) {
    // css will be in plugin’s PostCSS version
});

postcss.plugin will be like:

postcss.plugin = function (plugin) {
    return function (ast) {
        // here will be smarter semver check
        if ( ast.postcss.version == postcss.version ) {
            return plugin(ast);
        } else {
            var old    = postcss.parse( ast.toResult() );
            var result = plugin(old);
            return ast.postcss.parse( result.toResult() );
        }
    };
});

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Overkill !
We should not take care of this. It's up to the developer to know which version of the tool he use, & so which version of plugin to use too.

Your solution might create slow result if several postcss plugins use severals versions of postcss.
Sound like over-engineering to me.

We don't have to handle this kind of issue...

from gulp-postcss.

ai avatar ai commented on May 27, 2024

@MoOx but slow plugin is better, that broken plugin :)

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Also, you will have to face a new problem cause a new version might parse something a previous version fails to. You don't want user to want an report issue about that.

Plugin is not broken, just no compatible (yet?).

from gulp-postcss.

kristoferjoseph avatar kristoferjoseph commented on May 27, 2024

Sooo,
What steps does one need to take to get the documented example in the README to work without error?
Thanks :)

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Autoprefixer 5.0 was released with PostCSS 4.0 support. Please update.

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

@MoOx @ai should I revert commit that made postcss into peerDepency or is it fine for gulp plugin?

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

@kristoferjoseph PR for the README is very welcome!

from gulp-postcss.

ai avatar ai commented on May 27, 2024

@w0rm I am not so familiar with npm :(. @MoOx knows better.

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Note: I don't use gulp anymore so I don't care =)

Since npm plan to deprecate this feature, I think you should not use this.
And it brings the exact same kind of issue as normal dep: webpack/webpack#570 (comment)

from gulp-postcss.

TrySound avatar TrySound commented on May 27, 2024

If somebody needs old plugin, let use old versions of other plugins and postcss. Without peerDep

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

@MoOx so webpack loaders are the new hype thing =)

@TrySound to use with previous version of postcss simply pick corresponding version of gulp-postcss from the change log.

from gulp-postcss.

TrySound avatar TrySound commented on May 27, 2024

Yes, I am about it.

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

(@Worm my build process is more based on npm itself (npm scripts) than on webpack. Check it out https://github.com/MoOx/frontend-hot-starterkit)

Maybe we should close this issue for now (and encourage people to read CHANGELOG & README & package.json).

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Maybe an issue should be created to postcss directly.

from gulp-postcss.

ai avatar ai commented on May 27, 2024

I created this issue postcss/postcss#163

from gulp-postcss.

MoOx avatar MoOx commented on May 27, 2024

Perfect.

from gulp-postcss.

w0rm avatar w0rm commented on May 27, 2024

Put PostCSS back into simple dependency and republished on npm (commit)

from gulp-postcss.

ai avatar ai commented on May 27, 2024

Next PostCSS 4.1 will print warning if plugin throwed a error and was based on different PostCSS version: postcss/postcss@3d48436

from gulp-postcss.

sidoruk-sv avatar sidoruk-sv commented on May 27, 2024

The same issues can occur when you make a mistake in an array of processors and undefined item appear in a row:
[processor1,, processor2]

from gulp-postcss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.