CodeStitchOfficial / Advanced-Astro-v4-i18n

This Astro advanced kit includes a pre-configured multi-language setup, along with five pages filled with CodeStitch components. Everything is ready to go right from the start, complete with an i18n integration, LESS preprocessing and a blog powered by Astro’s content collections.
https://advanced-astro-kit-i18n.netlify.app/
Creative Commons Zero v1.0 Universal
19 stars 5 forks source link

Cannot read properties of undefined (reading 'translations') #2

Closed NHLopez closed 2 months ago

NHLopez commented 3 months ago

Hey guys! I cloned the project and installed the dependencies and got this error. No changes were to the code. Something I thought was interesting was my first time installing the project it worked fine. After receiving this error and multiple times of cloning, installing, nothing will change. I had even thought it was the fact I upgraded to astro 4.12.3, but after just starting over I'm stuck.

TypeError: Cannot read properties of undefined (reading 'translations')
    at Module.t (/mnt/d/Developement/Phlex Design/Client Projects/Advanced-Astro-v4-i18n-main/i18n:astro:124:14)
    at eval (eval at instantiateModule (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/vite/dist/node/chunks/dep-CzJTQ5q7.js:53441:24), <anonymous>:18:39)
    at 404 (eval at instantiateModule (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/vite/dist/node/chunks/dep-CzJTQ5q7.js:53441:24), <anonymous>:19:12)
    at callComponentAsTemplateResultOrResponse (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/runtime/server/render/astro/render.js:90:31)
    at renderToAsyncIterable (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/runtime/server/render/astro/render.js:132:32)
    at renderPage (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/runtime/server/render/page.js:31:30)
    at lastNext (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/core/render-context.js:135:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async callMiddleware (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/core/middleware/callMiddleware.js:21:10)
    at async RenderContext.render (file:///mnt/d/Developement/Phlex%20Design/Client%20Projects/Advanced-Astro-v4-i18n-main/node_modules/astro/dist/core/render-context.js:163:22)

I also noticed this: image image

Hopefully that helps, it was just something I noticed. Thank you!

BuckyBuck135 commented 3 months ago

Hi @NHLopez, Thanks for the report. I've run tests on my end, both on local copy and fresh clone, on both languages, and don't run into errors.

Could you please elaborate:

NHLopez commented 3 months ago

Hey @BuckyBuck135,

Not sure what happened but it works now? I just cloned it fresh and now its fine.

Before. it would give that error whenever the page transitions. For example, if I do npm start the homepage showed up, when I clicked about, I would see the about page slightly then it would throw the above error so I thought it might be the transitions but when I looked on astros website it was fine.

Either way it works now so thank you so much. Just incase it happens again would you know anything I could do?

BuckyBuck135 commented 3 months ago

Ok great! Without being able to reproduce the bug, it's difficult to say where it was coming from. let's hope it doesn't crawl back up again! :)

netmaster2000 commented 2 months ago

Hi @BuckyBuck135, can we re-open this issue? I had exactly the same errors in my project, so I cloned it fresh and I'm able to reproduce this bug (without making any changes to "Advanced-Astro-v4-i18n" code). Only "npm install" and "npm run dev". Then clicking any navbar menu item (especially the same page as the current page) throws this error. Pressing "Reload" button (or manually entering URL) loads the page correctly again without any errors.

OS: Win 11 Pro 64-bit Node: v20.17.0

Let me know what other information I can provide.

Screenshot 2024-09-04 134305 Screenshot 2024-09-04 134426 edit

BuckyBuck135 commented 2 months ago

Hi @netmaster2000, Thanks for your report. I've reopened the issue. I'm currently away for family reasons, so I won't have time to dig into this just now. In the meantime, if you do have some free time to run some debugging tests to try and pinpoint which page / component causes this issue, that would be a tremendous help.

BuckyBuck135 commented 2 months ago

After some quick tests, I looks like the issue does not impact the production site, which is good. I'll try to tackle this when I have some free time. npm run build + npm run preview shows you a copy of the deployed site on localhost.

netmaster2000 commented 2 months ago

You are right, the problem is only in "dev" mode. It looks like the i18n translations are not loaded on time. I'll try to debug it tomorrow.

netmaster2000 commented 2 months ago

I gave it a shot but couldn't figure it out. Something is wrong with "astrolicious/i18n", it is not loaded during the error, I don't know why. I tried to update it from your v0.4.3 to the latest 0.5.1, but it didn't help.

BuckyBuck135 commented 2 months ago

Hi guys, Thank you for your patience. I'm back at the keyboard after a family break.

The error seems to be coming from the custom 404 page. Short term: deleting this 404 page gets rid of the error.

Now, I'm working towards finding a more sustainable solution. I've opened an issue with the i18n package.

BuckyBuck135 commented 1 month ago

Hi everyone, Since Astro patched the issue upstream with this PR, I reinstated the custom translated 404 route in the kit. Make sure you upgrade Astro to at least v4.15.9, place 404.astro in the routes/ folder and the matching translation in locales/, as demonstrated in the kit.