Closed ricardopacheco closed 11 months ago
This is likely due to your vike project setup, not i18n-js. Can you please upload a sample project that raises this error?
@fnando Of course, it's a pleasure to do so. Here is the repository link: https://github.com/ricardopacheco/vike-18njs-debug
Use nodejs version 20.10.0 (I use Ubuntu 23.10 WSL2 Windows 11 with standard installation using asdf-nodejs);
Vike uses vitejs and node itself (SSR). I suspect it's the issue of the server with SSR, since I use vitejs in this same version in other SPA projects and i18n-js works perfectly. And coincidentally, I'm using the same version of nodejs (20.10.0) in these other SPA projects. So I believe it's either a configuration bug (some configuration is missing or I need to add something). would it be the path in nodejs?
@fnando Good News! I managed to fix the problem (running perfectly on both client and server). From what I understand... the server running nodejs doesn't understand ES6+ syntax and that's why it didn't work. That's right? I don't know that part well. https://github.com/ricardopacheco/vike-18njs-debug/pull/1/files
Afaict, node.js can only use import/export statements if you're files have the extension .mjs
. Otherwise, you'd need to do some compiling into something that the regular VM can understand.
Description
I'm migrating an application to use vike (with SSR option). I don't use anything special, which is in the official i18n-js documentation. In other projects, I have never come across this error.
How to reproduce
Just create a new vike app using official documentation and create a new component importing i18n-js.
What do you expect
Just works normally (I use the dependency in other projects following the doc and everything works perfectly (nextjs and react-create-app)
What happened instead
import { I18n } from "i18n-js"
Syntax Error
Software:
Full backtrace