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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve message for error "Nesting selectors can only be used inside a rule" #12208

Closed
webJose opened this issue Jun 27, 2024 · 5 comments
Closed
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@webJose
Copy link

webJose commented Jun 27, 2024

Describe the problem

The problem is the current state of the error. I just started a Svelte v5 branch for a large component library. I installed Svelte v5 and compiled. The error that I get is this:

CompileError: Nesting selectors can only be used inside a rule
    at e (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/errors.js:62:8)
    at Module.css_nesting_selector_invalid_placement (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/errors.js:521:2)
    at NestingSelector (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/phases/2-analyze/css/css-analyze.js:183:6)
    at go (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/phases/visitors.js:49:5)
    at visitor (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/phases/visitors.js:64:4)
    at visit (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/zimmerframe/src/walk.js:121:13)
    at file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/zimmerframe/src/walk.js:52:25
    at Array.forEach (<anonymous>)
    at Object.next (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/zimmerframe/src/walk.js:50:19)
    at go (file:https:///C:/Users/jpramire/src/repos/construction.svelte-dlux/node_modules/svelte/src/compiler/phases/visitors.js:45:29)

And what's the problem? That it doesn't say which file is the one with the problem. The stack trace doesn't contain it because logically, the file is not being executed. It is therefore a needed piece of information in the error message.

Describe the proposed solution

Include the problematic file in the error message:

Nesting selectors can only be used inside a rule in file "xxxx.svelte".

Importance

would make my life easier

UPDATE

Since I have dozens of files and zero clue about the one error'ing out, I'm very tempted to say that I the importance of this could be upgrated to "cannot use Svelte without this".

@dummdidumm
Copy link
Member

dummdidumm commented Jul 17, 2024

Which bundler are you using where this error appears like this? Using Vite I get the info where things are (rather; I got them until recently, there's a pending issue where v-p-s adjusts the stack in a way that makes it impossible for Vite to do the right thing; update: it's a bug in vite-plugin-inspect, so unrelated)

@dummdidumm dummdidumm added the awaiting submitter needs a reproduction, or clarification label Jul 17, 2024
@webJose
Copy link
Author

webJose commented Jul 17, 2024

Hello, sir! Indeed, this is (or was, I suppose) with Vite v5. I didn't get the culprit in the message. :-( Could it be because of the pending thing you mentioned?

@dummdidumm
Copy link
Member

I realized that this is a bug in vite-plugin-inspect, so if you don't use that then no, you should see the correct error message, both in the console and in the Vite error overlay.

@webJose
Copy link
Author

webJose commented Jul 17, 2024

I understand. Not sure about what to tell you. I'm not using vite-plugin-inspect, yet what you see there is what I got: No culprit file anywhere in sight. The problem now is that I have already fixed this.

I guess I can try to reproduce again. Let me locate the commit that fixes this and see if I can revert.

@webJose
Copy link
Author

webJose commented Jul 17, 2024

@dummdidumm I reverted the CSS change and tested with next.166, which is the one I was using when I reported this. It is showing up now. Unsure what was going on back then.

This part was missing when I reported:

error during build:
[vite-plugin-svelte] [plugin vite-plugin-svelte] src/routes/checkboxes/+page.svelte (294:20): src/routes/checkboxes/+page.svelte:294:20 Nesting selectors can only be used inside a rule
file: C:/Users/jpramire/src/repos/construction.svelte-dlux/src/routes/checkboxes/+page.svelte:294:20

Since then, newer Svelte's show even a preview of the code, so I guess we can forget about this one. I'm closing. Thanks for looking into it.

@webJose webJose closed this as completed Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

2 participants