stylelint-config-standard-scss icon indicating copy to clipboard operation
stylelint-config-standard-scss copied to clipboard

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

Open ayjee opened this issue 4 years ago • 14 comments

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`,
  },
};

ayjee avatar Nov 02 '21 18:11 ayjee

same for me, any suggestion? 😕

ivanlori avatar Nov 03 '21 11:11 ivanlori

I have the same issue

Ev1ch avatar Nov 03 '21 21:11 Ev1ch

Can you provide minimal reproducible test case?

niksy avatar Nov 04 '21 07:11 niksy

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

ayjee avatar Nov 04 '21 13:11 ayjee

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

niksy avatar Nov 04 '21 14:11 niksy

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

michalkopanski avatar Nov 04 '21 15:11 michalkopanski

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

Ev1ch avatar Nov 04 '21 22:11 Ev1ch

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

niksy avatar Nov 05 '21 08:11 niksy

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

ayjee avatar Nov 05 '21 14:11 ayjee

@niksy Thank you

yarn add -D postcss@8 did the trick

stephenjason89 avatar Dec 23 '21 03:12 stephenjason89

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

toffyui avatar Jan 31 '22 12:01 toffyui

@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.

dcwarwick avatar Feb 06 '22 23:02 dcwarwick

@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
}

danielgroen avatar May 19 '22 08:05 danielgroen

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

12914hh avatar Jun 22 '22 16:06 12914hh