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
Unable to bundle stylelint
using bundlers
#6440
Comments
@phoenisx Thanks for opening the issue and for using the template. Your suggestion sounds good to me. Could you please provide a minimal reproduction repository using rollup? |
Hi @ybiquitous I created a repro for this issue here: https://github.com/phoenisx/stylelint-bundling-issue You need to run the following commands to get to the reproduction: pnpm build #use `npm` if you prefer
pnpm run-bundle You will get the following error:
I have also tried adding |
@phoenisx Thank you for providing the reproduction with a detailed explanation! Converting the code to the following bundler-friendly pattern seems to make sense. 👍🏼 - 'alpha-value-notation': importLazy('./alpha-value-notation'),
+ 'alpha-value-notation': importLazy(() => require('./alpha-value-notation'))(), In addition, to avoid type errors, we need to apply the patch to the declare function importLazy<T = unknown>(
importFn: (moduleId: string) => T
-): (moduleId: string) => T;
+): (moduleId?: string) => T; Let's create and commit a patch by using the I've labeled the issue as ready to implement. Please consider contributing if you have time. There are steps on how to fix a bug in a rule in the Developer guide. |
Thanks for the guidance. I can work on this and raise a fix later. |
I have raised the PR. Do let me know if anything else is needed to resolve this issue 💯 |
What steps are needed to reproduce the bug?
Use
rollup
to bundle this library. It failsWhat Stylelint configuration is needed to reproduce the bug?
None
How did you run Stylelint?
I am trying to bundle stylelint in my project
Which version of Stylelint are you using?
14.14.0
What did you expect to happen?
Stylelint should get bundled, without any errors.
What actually happened?
Getting
Could not dynamically require "./color-no-invalid-hex"
when usingcolor-no-invalid-hex
in the project.Does the bug relate to non-standard syntax?
None
Proposal to fix the bug
stylelint
: Standardise lazy requires #4729Since the latter does not use the
import-lazy
pattern for bundlers, bundlers are not able to resolve the require paths and fails during runtime.Possible Resolution:
import-lazy
pattern for bundlers intact, i.e. to revert back to usingimportLazy(() => require('./color-no-invalid-hex'))()
patternI am not sure how strict this project is in terms of using
@ts-ignore
comments, but I feel this is a decent trade-off to support proper bundling, unless someone has a better solution to overcome typescript type errors inrules
module.The text was updated successfully, but these errors were encountered: