kristerkari / stylelint-react-native

A collection of React Native specific linting rules for stylelint (in a form of a plugin).
MIT License
57 stars 1 forks source link

Support Stylelint v16 #182

Closed JoseLion closed 5 months ago

JoseLion commented 6 months ago

Currently, this plugin does not work with Stylelint v16. The error below is thrown when using the following versions:

Error: Cannot find module 'C:\Repos\paytogether\paytogether-app\node_modules\stylelint\lib\utils\declarationValueIndex'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1180:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1168:15)
    at resolveExports (node:internal/modules/cjs/loader:590:14)
    at Module._findPath (node:internal/modules/cjs/loader:667:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1129:27)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1234:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Repos\paytogether\paytogether-app\node_modules\stylelint-react-native\dist\rules\font-weight-no-ignored-values\index.js:10:29)
    at Module._compile (node:internal/modules/cjs/loader:1375:14)
RayKay91 commented 6 months ago

Think it's to do with the fact that stylelint is migrating to ESM, and they've now renamed all their files to have .cjs/.mjs extensions.

You can manually make it work by making the following changes:

// node_modules/stylelint-react-native/dist/rules/dont-weight-no-ignored-values/index.js

// ...
var declarationValueIndex = import("stylelint/lib/utils/declarationValueIndex.cjs"); // explicit import of commonJS file.
// ...
// node_modules/stylelint/lib/augmentConfig.mjs

//...
// pluginImport = pluginImport.default || pluginImport
pluginImport = pluginImport.default.default || pluginImport.default || pluginImport // for some reason there are two layers of default with this module. Checking for this seems to resolve it for me.
// ...

// ...
kristerkari commented 5 months ago

Thanks for reporting, I'll update the plugin to support v16.

kristerkari commented 5 months ago

There is a new release with the fix: https://github.com/kristerkari/stylelint-react-native/releases/tag/v2.7.0

Please let me know if there is something more that you need help with.