-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Bug]: TypeError: Cannot read properties of undefined (reading 'root') #1618
Comments
I am having the same error. Strangely mine happens after making a call to firebase firestore (using firebase-admin). Error goes away when I comment out the tag as well. |
I have the same error too after adding framer-motion to my code. <motion.div animate={{ rotate: 360 }} transition={{ duration: 2 }}>
<h1>Welcome to remix!</h1>
</motion.div> results in:
|
This error typically occurs when you have server side dependencies that got bundled in your client scripts. The file with the getPosts() function, what is it named? Does it use the .server suffix, like |
@kiliman, that was my case, as I've added some prisma code to my app and haven't noticed that it broke it. |
I had the same issue, but the @kiliman solution worked for me. I renamed the file from |
I'm having this problem as well, however my file already has the https://github.com/nheingit/blog This is the repo for the code. The error occurs on /blog/test-mdx Everything renders correctly, but I still get the error message. |
@kiliman Thanks for the response! Let me know if I can be of any help. |
I am getting the same error. I tried debugging and I found the same issue that Following is the url where I am getting the error -- Couple of pointers:
Let me know if I can help in some way. Thanks! |
I believe the issue arises because the browser is processing that module, and it tries to import the routes. However, something is failing in the route module. Most likely server code got bundled with the client. Because it fail loading, it stops executing that module and never runs the statement that initializes the I suggest that the code that initializes RemixEntryContext should probably check to see if routeData and routeModules are properly defined, and throw an error with the message 'Cannot initialize routeModules. This normally occurs when you have server code in your client modules. See this link for more details: ' At least that's a better error than this cryptic message. I'm not sure if you can wrap import statements in try/catch. |
@killman would like to follow up on this. If all of this is true, I'm bundling server code into my client somewhere. However, my imports do have the Any ideas as to what is causing my underlying issue? |
Update: I was also importing After setting up a .server.ts file where I can import all of my server code, and then import from THERE, everything works. |
I'm getting the same error when trying to introduce components that use react-three-fiber. Assuming they are packaged with node-only APIs or something along those lines? |
I ran into this issue as well when trying to port code to another repo. The fix for me was to add this to
It seems to be what Remix needs in order to properly strip out server code in the client (tree-shaking). I noticed the error would occur for every file in |
Was experiencing this issue in Remix + MUI example. PR mentioned above helped, thanks! In my case it was import * as React from 'react' Files with this import were used in SSR. Refactored to using named imports and everything works. |
Was running into the same issue trying to import |
Just came across this issue while experiencing the same thing. In my case, I'm not doing any server-side thing. I'm just creating a websocket and calling APIs, right when the component has mounted on the browser. I also tried doing: export default function Index() {
// ..
if (typeof document === 'undefind') return <></>
// render component
} but it still didn't work. Is there any way we can inspect the |
@dillionmegida From my understanding, this issue can also come up if any JS is breaking in this particular component. Check the developer console to see if there are any JS errors proceeding this error. If yes, fixing those might resolve the issue. Also, you can move your code into client-only module to make it exclusively run in the browser. Check this -- |
What are the chances that the typo in your code here is also in your code there? Because that's exactly what would happen to me somehow. lol |
I also have this error, but on my side, I've just added a resource route. It's only when I add a default function to the resource route file that my app works again. |
This occurs for me when importing an Icon from @heroicons, but only in my Vercel build and not a traditional Remix build In the @heroicons library the icons *.d.ts file uses |
Adding |
I'm experiencing the same issue. |
The original issue reported is now covered in the gotcha section |
I get that this is a common issue and mentioned in the docs. However, the error message itself is misleading, because Remix isn't verifying that If the code added a check and threw a more meaningful error, this wouldn't be so confusing to first time users. From comment above:
|
You're totally right @kiliman, keeping this open and accepting PRs 🙏🏼 |
🤖 Hello there, We just published version Thanks! |
I'm running into this same error. I've deployed a Remix site to Cloudflare pages. Everything works fine in Chrome and Safari. Firefox give me the following error: Error: Cannot initialize 'routeModules'. This normally occurs when you have server code in your client modules. Interestingly this only happens in Firefox when I visit a specific page and only if I use a custom domain. If I use the workers.dev domain provided by Cloudflare the page loads fine. |
I did some more testing and found that turning off the Cloudflare 'Rocket Loader' under speed optimizations fixed the problem in Firefox. I'm guessing in my case this is a Cloudflare bug. |
Encountered a similar error to this when using third party components react-select and react-datepicker. Add a Could we re-open, or open a new issue for this as it is still causing problems. |
@louisjrdev This is now a documented gotcha (see docs) and the error message was enhanced. Feel free to open a new issue if you thing something is broken, and not covered by the documentation. |
@machour There is certainly still a bug here, I should not have to |
@louisjrdev this is not what this issue was about, please read the originally reported problem, that's what we fixed. |
* implement set or unset parent event * fix: cannot read properties of undefined (reading: 'root') see remix-run/remix#1618 (comment) * show parent and child events * create parent or child event * warn that child events were deleted * fix: TypeError: Invalid URL: /event/create * fix: Array.prototype.map() expects a return value from arrow * add missing anon test * implement add child event * implement remove child event * filter events having parent * fix: test checking options failed * publish recursive
omfg thank you for posting this. I've been having the same issue for WEEKS!!!! |
Which Remix packages are impacted?
remix
(Remix core)What version of Remix are you using?
What version of Node are you using? Minimum supported version is 14.
v16.4.2
Steps to Reproduce
I was just trying to follow the first tutorial, and right after the part when you create the posts .md files everything was working ok. But after you add the code mentioned in the tutorial:
Then the application breaks and starts showing this error on localhost/posts
The error is not helpful at all so I spend some time debugging it and I find out that it was because the
<Scripts />
component in the root.tsx fileIf you comment out the
<Scripts />
tag the app starts working again but still don't know exactly whyExpected Behavior
The app should not break or it should show a helpful error that helps identify the bug
Actual Behavior
The app breaks showing this error:
The text was updated successfully, but these errors were encountered: