Could the "use client" compilation error take tree-shaking into account? #75071
Unanswered
jjenzz
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
backstory: i'm using webpack still and i've been fiddling with different conventions for structuring projects. i realised that if i do the following i get the compilation error about a missing
"use client"
directive:now i know it is referring to the fact that i am not using
"use client"
here, but i was surprised to see this error given theClientComponent
isn't being imported or used anywhere. my understanding is that it would be tree-shaken from the bundle. this led me to try the following:and that worked! the
"use client"
error goes away 🎉 this is exactly what i want, but trying to remember that named imports can cause things to throw (seemingly unnecessarily) is a bit of a pain.@leerob is there anything that can be done to improve this error handling on nextjs side so that it only errors if the client import hasn't been tree-shaken? is there a reason why the import types are treated differently? keen to understand this better so any help is super appreciated☺️
the downside to using
import * as NextNavigation
is that i no longer get the built-in "use client" compilation error when using theClientComponent
in an RSC. it errors, but its an obscure error that doesn't make the actual issue clear.Beta Was this translation helpful? Give feedback.
All reactions