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

TypeError: Class extends value undefined is not a constructor or null #5

Open
ayjee opened this issue Nov 2, 2021 · 14 comments
Open

Comments

@ayjee
Copy link

ayjee commented Nov 2, 2021

I am upgrading to stylelint v14, and moving from stylelint-config-standard to stylelint-config-standard-scss. When I attempt to run stylelint I get the following error, which I can only reproduce with stylelint-config-standard-scss:

 $ stylelint --config stylelint.config.js 'app/assets/stylesheets/**/*.{scss,css}' 'api/assets/**/*.{scss,css}' --fix
TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/Users/ayjee/work/repos/test-repo/node_modules/postcss-scss/lib/nested-declaration.js:3:33)
    at Module._compile (/Users/ayjee/work/repos/test-repo/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (/Users/ayjee/work/repos/test-repo/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/ayjee/work/repos/test-repo/node_modules/postcss-scss/lib/scss-parser.js:4:25)
    at Module._compile (/Users/ayjee/work/repos/test-repo/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
error Command failed with exit code 1.

Any idea as to what might be causing this issue? Here is my config file:

// stylelint.config.js

'use strict';

module.exports = {
  extends: [`stylelint-config-standard-scss`],
  rules: {
    'string-quotes': `double`,
  },
};
@ivanlori
Copy link

ivanlori commented Nov 3, 2021

same for me, any suggestion? 😕

@Ev1ch
Copy link

Ev1ch commented Nov 3, 2021

I have the same issue

@niksy
Copy link
Member

niksy commented Nov 4, 2021

Can you provide minimal reproducible test case?

@ayjee
Copy link
Author

ayjee commented Nov 4, 2021

@niksy I tried to post that in my original comment. Is there something else you would like to see?

@niksy
Copy link
Member

niksy commented Nov 4, 2021

@ayjee we need whole directory and package structure so we’re sure there isn’t any conflicting dependencies and things like that.

@michalkopanski
Copy link

@niksy are there any known conflicting dependencies? I'm having the same issue as well.

@Ev1ch
Copy link

Ev1ch commented Nov 4, 2021

Can you provide minimal reproducible test case?

Of course.

Developing dependencies:

"devDependencies": { "eslint": "^7.11.0", "eslint-plugin-react": "^7.26.1", "lint-staged": "^11.2.6", "prettier": "^2.4.1", "stylelint": "^14.0.1", "stylelint-config-standard-scss": "^2.0.1" },

Main dependencies:

"dependencies": { "@testing-library/jest-dom": "^5.15.0", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "clsx": "^1.1.1", "node-sass": "^6.0.1", "normalize-scss": "^7.0.1", "prop-types": "^15.7.2", "react": "^17.0.2", "react-dom": "^17.0.2", "react-router-dom": "^5.3.0", "react-scripts": "4.0.3", "web-vitals": "^1.1.2" },

.stylelintrc:

{ "extends": "stylelint-config-standard-scss" }

That's all, to be true. I was impressed, because it is the most standard setup I can imagine. I was thinking about node-sass package. Maybe it is too new or something

@niksy
Copy link
Member

niksy commented Nov 5, 2021

This is related to how npm installs and flattens dependencies. postcss-scss expects postcss as peer dependancy, and since you didn’t install it yourself, and most of other dependencies use postcss@7, that version is placed at root of node_modules, but our postcss-scss needs postcss@8.

Here are possible fixes:

  • Install postcss@8 as your project dependancy so postcss-scss can pick that as top-level postcss
  • Update all other related packages which use postcss@7 to versions where postcss@8 is expected

@ayjee
Copy link
Author

ayjee commented Nov 5, 2021

This seems to fix it for me @niksy. Thanks so much!

@stephenjason89
Copy link

stephenjason89 commented Dec 23, 2021

@niksy Thank you

yarn add -D postcss@8
did the trick

@yuikoito
Copy link

@niksy Thank you. You saved me so much time!

@dcwarwick
Copy link

@niksy thanks for this -- I encountered this while upgrading stylelint and the error message is supremely non-obvious!

Slight variation in my situation: bit monorepo, and there are various dependencies at various levels some of which pull in postcss v7 and some v8, and lerna was hosting the v7 as chance would have it. Adding postcss@8 to the top-level package.json resolves. Many thanks.

GeorgeWL pushed a commit to GeorgeWL/react-playing-cards that referenced this issue Feb 20, 2022
naseberry added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this issue Mar 30, 2022
`postcss-scss` expects `postcss@8`, this therefore caused the error `TypeError: Class extends value undefined is not a constructor or null` when running Stylelint

see: stylelint-scss/stylelint-config-standard-scss#5 (comment)
ivanELEC added a commit to ministryofjustice/laa-court-data-ui that referenced this issue Apr 7, 2022
stylelint-config-gds includes postcss-scss, this expects postcss as peer
depdendency, by default, other dependencies use the wrong version. Needed
to install as dependency so that the correct version is available. More
info here:
stylelint-scss/stylelint-config-standard-scss#5
ivanELEC added a commit to ministryofjustice/laa-court-data-ui that referenced this issue Apr 7, 2022
stylelint-config-gds includes postcss-scss, this expects postcss as peer
depdendency, by default, other dependencies use the wrong version. Needed
to install as dependency so that the correct version is available. More
info here:
stylelint-scss/stylelint-config-standard-scss#5
ivanELEC added a commit to ministryofjustice/laa-court-data-ui that referenced this issue Apr 7, 2022
* Bump stylelint, stylelint-config-gds and stylelint-order

Bumps [stylelint](https://github.com/stylelint/stylelint), [stylelint-config-gds](https://github.com/alphagov/stylelint-config-gds) and [stylelint-order](https://github.com/hudochenkov/stylelint-order). These dependencies needed to be updated together.

Updates `stylelint` from 13.13.1 to 14.6.1
- [Release notes](https://github.com/stylelint/stylelint/releases)
- [Changelog](https://github.com/stylelint/stylelint/blob/main/CHANGELOG.md)
- [Commits](stylelint/stylelint@13.13.1...14.6.1)

Updates `stylelint-config-gds` from 0.1.0 to 0.2.0
- [Release notes](https://github.com/alphagov/stylelint-config-gds/releases)
- [Changelog](https://github.com/alphagov/stylelint-config-gds/blob/main/CHANGELOG.md)
- [Commits](alphagov/stylelint-config-gds@0.1.0...0.2.0)

Updates `stylelint-order` from 4.1.0 to 5.0.0
- [Release notes](https://github.com/hudochenkov/stylelint-order/releases)
- [Changelog](https://github.com/hudochenkov/stylelint-order/blob/master/CHANGELOG.md)
- [Commits](hudochenkov/stylelint-order@4.1.0...5.0.0)

---
updated-dependencies:
- dependency-name: stylelint
  dependency-type: direct:development
  update-type: version-update:semver-major
- dependency-name: stylelint-config-gds
  dependency-type: direct:development
  update-type: version-update:semver-minor
- dependency-name: stylelint-order
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Explicitly add postcss to dependencies
stylelint-config-gds includes postcss-scss, this expects postcss as peer
depdendency, by default, other dependencies use the wrong version. Needed
to install as dependency so that the correct version is available. More
info here:
stylelint-scss/stylelint-config-standard-scss#5

* Fixed stylelint issues in phase banner

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ivanELEC <ivan.yohuno@digital.justice.gov.uk>
kawa-work referenced this issue in kawa-work/population-graph May 1, 2022
add dependency and set up stylelint config
@danielgroen
Copy link

danielgroen commented May 19, 2022

@niksy Thank you

yarn add -D postcss@8 did the trick

I am using Nuxt 2 and Webpack
This works for me. however when i add postcss i got a dozen warnings of:
afbeelding

To fix this:
add the following to your nuxt.conf.js:

build: {
    postcss: null
}

@12914hh
Copy link

12914hh commented Jun 22, 2022

Thank you so much. I take all night to resolve this problem。 thanks! QAQ

spaceo added a commit to reload/dpl-design-system that referenced this issue Jul 11, 2022
spaceo added a commit to reload/dpl-design-system that referenced this issue Jul 11, 2022
spaceo added a commit to reload/dpl-design-system that referenced this issue Jul 11, 2022
spaceo added a commit to danskernesdigitalebibliotek/dpl-design-system that referenced this issue Jul 12, 2022
seokzin added a commit to modorie/moida that referenced this issue Sep 5, 2022
- TypeError: Cannot read properties of undefined (reading 'stringify')
- post-css 버전 의존성 이슈
  (stylelint-scss/stylelint-config-standard-scss#5 (comment))
cee-chen added a commit to cee-chen/eui that referenced this issue Dec 2, 2022
cee-chen added a commit to cee-chen/eui that referenced this issue Dec 2, 2022
cee-chen added a commit to cee-chen/eui that referenced this issue Dec 7, 2022
cee-chen added a commit to cee-chen/eui that referenced this issue Dec 8, 2022
cee-chen added a commit to cee-chen/eui that referenced this issue Dec 8, 2022
cee-chen pushed a commit to elastic/eui that referenced this issue Dec 12, 2022
* Add `stylelint` and scss configs

- see https://github.com/stylelint/stylelint/blob/main/docs/user-guide/get-started.md#using-a-community-shared-config

- note that adding postcss@8 is necessary for the scss config to work - see stylelint-scss/stylelint-config-standard-scss#5

* Convert `.stylelintrc` to `.stylelintrc.js` + add scss configs

- JS file helps us do things like leave meaningful comments, which JSON doesn't allow

* Update ignored files

- previously ignored files were added due to vscode's overeager linting - it looks like said plugin no longer does so, so we can remove non `.scss` files

- port over sass-lint excludes
  - add missed datepicker dir
  - add non-src files
  - remove no-longer-existant chart dir

* Remove sass-lint, swap over yarn shortcuts

* Convert camelCase name linting

* Convert indentation lint rule
+ fix issues caught by stylelint but not by sass-lint

- unlike sass-lint, stylelint checks indentation of comments and also checks for tabs vs spaces

+ fix a few unnecessary `()`s, and add a disable because stylelint is confused by scss maps

+ remove unnecessary indentation disables

* Convert single quotes lint rule
+ add skip for Sass scenarios where `"` has to be used for interpolation

* Convert brace style lint rule

- there isn't a handy `1tbs` option like eslint/sass-lint, so we need to combine a few different rules to get the effecrt we want

+ fix various instances where stylelint caught unnecessary double spaces before braces

* Convert various value lint preferences

+ include some rules that stylelint is more strict about than sass-lint was

* Fix pseudo-element lint rule

- sass-lint was incorrectly marking pseudo *classes* as needing two `::`, whereas only pseudo *elements* need two `::`s. stylelint appears to correctly catch this OOTB

@see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements

* Convert newline between rulesets/blocks lint rule

* [opinionated] Add several new lint rules catching extra newlines/whitespace

- prettier does the same/similar for JS/CSS-in-JS in any case

* Add lint rule for 1 selector per line

- already appears to be something we do or was enforced by sass-lint, but stylelint needs the explicit rule

* Convert/fix rules around syntax whitespaces

* [opinionated] Fix several comment rules stylelint ships with OOTB

- specifically around empty comments & spacing around comments - I find them to be valid and inline with JS linting

* Fix `no-duplicate-selectors` caught by stylelint (but not sass-lint)

* Override default stylelint rules for  backwards-compatability

- without these added rules, we get stylelint errors for how we currently write our CSS

- although we may want to consider removing these in the future & using more modern syntax

* Fix vendor prefix linting by converting to stylelint-disable syntax

* Disable various opinionated stylelist defaults

- that were not previous enforced by sass-lint

- we can consider turning them on at a later time if we want

* Convert no `!important` rule and overrides

+ remove unnecessary disables

* Convert nesting depth rule

- default with sass-lint but not with stylelint or existing configs

+ remove unnecessary disables

+ add newly necessary disables (some it's unclear why sass-lint didn't catch, and some are due to sass syntax, which stylelint unfortunately does not care about)

* Convert Sass empty ruleset lint rule

- by default, stylelint considers comments to not make the block empty

* Convert qualifying elements selector lint rule

* Clarify function name lint rule

+ remove disables

* Attempt to convert

- this is not perfect - stylelint does not appear to have a 1:1 with sass-lint on this, but it's somewhat close and will become less of an issue as we migrate to Emotion

+ remove disable lines that no longer apply

* Remove unnecessary sass lint disables

- no-mispelled-properties is simply wrong / out of date

- no-warn was already disabled in -sass-lint.yml

- empty-args isn't useful in a post-sass world

* 🚫 Remove mixin order rule

- there's no corresponding stylelint rule, and it feels pedantic / not terribly useful

* 🚫 Remove border 0 rule

- there's no corresponding stylelint rule, and it feels pedantic / not useful

* Remove all remaining disabled sass-lint rules

- these don't appear to be enforced by stylelint, and as such nothing needs to be done

* Delete all sass lint config files

* Add some more stylelint docs links & notes

* Remove `prettier-stylelint`

- It's not clear to me why that plugin was added or what it does, and it was last updated 5 years ago and uses a super old version of stylelint (8.x), so I'm removing it

* [PR feedback] Remove `number-leading-zero` rule

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

No branches or pull requests

10 participants