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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

require('css-functions-list') returns "/index.json" #2

Closed
100terres opened this issue Feb 12, 2022 · 7 comments
Closed

require('css-functions-list') returns "/index.json" #2

100terres opened this issue Feb 12, 2022 · 7 comments

Comments

@100terres
Copy link

100terres commented Feb 12, 2022

Hi! 馃檪

I'm running into an issue where we are not able to load the index.json from the root of this package, because when requiring the package it returns "/index.json" which the right relative or absolute path.

The issue I'm describing happens when using the stylelint@v14.5.0 node API in a jest@v26.6.3 test with node@v14.18.2. (On ubuntu 20.04)

EDIT: It's also uder TypeScript@4.5.5 with babel

stylelint recently added this new function-no-unknown rule which uses under the hood the css-functions-list package here:

It was introduced in this PR

When I execute my code using the function-no-unknown (that was enabled in the stylelint-config-recommended package here) it throws this error

ENOENT: no such file or directory, open '/index.json'

Which is a similar to error raised by someone in the PR stylelint/stylelint#5865 (comment)

I've found a way to make it work using path.resolve instead of the new URL here and directly use the returns of require("css-functions-list") here

Would it make sens to use the path.resolve instead?

@100terres
Copy link
Author

I've also open an issue on the stylelint repo stylelint/stylelint#5904

@niksy
Copy link
Owner

niksy commented Feb 12, 2022

I think this is related to how Jest handles URL. I could use path.resolve, but using current approach is valid with ESM modules. Please see first if there is something wrong on Jest side.

As for similar issue in Stylelint repo, that issue was solved using URL which, again, is valid approach.

@100terres
Copy link
Author

100terres commented Feb 12, 2022

Thank you for your answer and I understand. I've look around a bit and I found that it might also be related to TypeScript (I forgot to mention that I was using it).

Issue following jest ESM support

@niksy
Copy link
Owner

niksy commented Feb 12, 2022

@100terres just tried importing module with ESM and CommonJS approach鈥攂oth work as expected. This is probably something unrelated to how this module exports path to JSON, otherwise this wouldn鈥檛 work in Stylelint. README contains example on how to consume JSON file.

Sorry if this isn鈥檛 working with you. If there is more reported cases of this "problem", I will see if I can approach this differently (in fact, I can, but I鈥檓 trying to follow ESM specification). Otherwise, this stays as it is.

@niksy niksy closed this as completed Feb 12, 2022
@niksy
Copy link
Owner

niksy commented Feb 14, 2022

@100terres new version has been published where I鈥檝e changed the way JSON file is resolved, could you try again?

@100terres
Copy link
Author

Hi @niksy here's my follow up on this issue in the stylelint repo stylelint/stylelint#5904 (comment)

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

No branches or pull requests

2 participants