Skip to content

feat: add stylelint v17 support#377

Merged
ricardogobbosouza merged 6 commits intowebpack:mainfrom
zalishchuk:feat/stylelint-v17
Feb 2, 2026
Merged

feat: add stylelint v17 support#377
ricardogobbosouza merged 6 commits intowebpack:mainfrom
zalishchuk:feat/stylelint-v17

Conversation

@zalishchuk
Copy link
Contributor

Note

This PR was created with assistance from Claude. Please review thoroughly.

Summary

Add support for stylelint v17, which removed CommonJS support and is now ESM-only.

This PR uses dynamic import() to load stylelint, enabling support for ESM-only stylelint v17 while maintaining backward compatibility with v13-v16.

Closes #376

Technical notes

  • tsconfig.json adds skipLibCheck: true because stylelint v17's type definitions import GlobbyOptions from globby, but globby v16 exports Options instead
  • Tests use stylelintPath option instead of jest.mock() because Jest's module mocking doesn't intercept dynamic import() calls in CommonJS context. I investigated jest.unstable_mockModule() which does work, but it requires running Jest in native ESM mode (--experimental-vm-modules) which would require adding .js extensions to all test utility imports. Using stylelintPath is more practical - it uses stable APIs and tests a real plugin feature.

What kind of change does this PR introduce?

feat (new feature)

Did you add tests for your changes?

Yes. All 55 existing tests pass. Tests were updated to use the stylelintPath option for mocking instead of jest.mock(), since Jest's module mocking doesn't work reliably with dynamic import().

Does this PR introduce a breaking change?

Yes. Minimum Node.js version is now 20.19.0 (required by stylelint v17).

If relevant, what needs to be documented once your changes are merged or what have you already documented?

  • Updated README.md to document the Node.js >= 20.19.0 requirement
  • Bumped peer dependencies to include stylelint ^17.0.0
  • Bumped engines to node >= 20.19.0
  • Should bump to major version (v6.0.0) due to breaking Node.js requirement
  • CHANGELOG should document the breaking change and migration path

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 26, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

Use dynamic import() to load stylelint, enabling support for ESM-only
stylelint v17 while maintaining backward compatibility with v13-v16.

- Switch from require() to dynamic import() for loading stylelint
- Update formatter loading to handle promise-based formatters (v16+)
- Add module: node16 to tsconfig for dynamic import support
- Bump minimum Node.js version to 20.19.0 (required by stylelint v17)
- Update tests to use stylelintPath option for mocking

Closes webpack#376

BREAKING CHANGE: Minimum Node.js version is now 20.19.0
tsconfig.json Outdated
"types": ["node"],
"resolveJsonModule": true
"resolveJsonModule": true,
"skipLibCheck": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-akait How should we handle this error?

Error: node_modules/stylelint/types/stylelint/index.d.ts(2,15): error TS2305: Module '"globby"' has no exported member 'GlobbyOptions'.
Error: node_modules/stylelint/types/stylelint/index.d.ts(2,36): error TS1541: Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.
ERROR: "build:types" exited with 1.```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that stylelint itself uses skipLibCheck: true in their tsconfig as of stylelint/stylelint#8875

@codecov
Copy link

codecov bot commented Jan 26, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@alexander-akait
Copy link
Member

@ricardogobbosouza Can you look at this too?

@zalishchuk
Copy link
Contributor Author

@ricardogobbosouza
Copy link
Collaborator

@ricardogobbosouza Can you look at this too?

It seems good..

@ricardogobbosouza
Copy link
Collaborator

stylelint/stylelint#8992 stylelint/stylelint#8991

Waiting for this typing problem in styelint version 17

@alexander-akait
Copy link
Member

Yeah, let's wait a fix from stylelint team

@jeddy3 jeddy3 mentioned this pull request Jan 27, 2026
4 tasks
@zalishchuk
Copy link
Contributor Author

@ricardogobbosouza @alexander-akait stylelint/stylelint#9007
I've updated the stylelint version, but it was still throwing a TypeScript error:

node_modules/stylelint/types/stylelint/index.d.ts:2:47 - error TS1541: Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.

2 import type { Options as GlobbyOptions } from 'globby';
                                                ~~~~~~~~
                                                
Found 1 error in node_modules/stylelint/types/stylelint/index.d.ts:2

Updated the tsconfig.json to use "module": "nodenext",

@alexander-akait
Copy link
Member

@ricardogobbosouza Can you review code and make a release when you will have time, thank you

@zalishchuk
Copy link
Contributor Author

Previously, require() was used to load stylelint, which would immediately throw an error if the module was broken or missing, necessitating try/catch for error handling.

Now, with import(), stylelint loads lazily, and the setup() function only stores the path as a string without loading the module. The try/catch can no longer catch such errors.

Load errors are still managed as they propagate through the .catch() of lintFiles() and are reported via compilation.errors.

@yoyo837
Copy link

yoyo837 commented Feb 2, 2026

Should we also add Stylelint 17 to the CI matrix for Node.js 20/22/24?

@ricardogobbosouza
Copy link
Collaborator

Thanks @zalishchuk

@ricardogobbosouza ricardogobbosouza merged commit 27d4787 into webpack:main Feb 2, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support stylelint 17

4 participants