N
Nuxt4mo ago
Bazze

Using nuxtjs/i18n types in a module

My last few braincells are fighting eachother over this problem.. Working on a nuxt module that uses nuxtjs/i18n. I am using
import type { LocaleObject } from "@nuxtjs/i18n";
import type { LocaleObject } from "@nuxtjs/i18n";
Typescript does not throw any errors during development. Trying to build the module, it suddenly throws
ERROR Unexpected token (2:12) in \node_modules\@nuxtjs\i18n\dist\types.d.ts 13.22.55

at pp$4.raise (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:21621:13)
at pp$9.unexpected (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18829:8)
at pp$9.expectContextual (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18783:41)
at Parser.parseImport (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:26127:14)
at pp$8.parseStatement (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:19005:49)
at pp$8.parseTopLevel (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18886:21)
at Parser.parse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18658:15)
at Function.parse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18708:35)
at Graph.contextParse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:25754:38)
at tryParse (/node_modules/unbuild/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12)
ERROR Unexpected token (2:12) in \node_modules\@nuxtjs\i18n\dist\types.d.ts 13.22.55

at pp$4.raise (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:21621:13)
at pp$9.unexpected (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18829:8)
at pp$9.expectContextual (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18783:41)
at Parser.parseImport (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:26127:14)
at pp$8.parseStatement (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:19005:49)
at pp$8.parseTopLevel (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18886:21)
at Parser.parse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18658:15)
at Function.parse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:18708:35)
at Graph.contextParse (/node_modules/unbuild/node_modules/rollup/dist/es/shared/node-entry.js:25754:38)
at tryParse (/node_modules/unbuild/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12)
I have no idea whats going on.. Taking a look at the referred types file. The problem is being pointed to the opening bracket { in the import statement.
import type { ModuleOptions, ModuleHooks, RuntimeModuleHooks, ModulePublicRuntimeConfig } from './module'

...
import type { ModuleOptions, ModuleHooks, RuntimeModuleHooks, ModulePublicRuntimeConfig } from './module'

...
No description
16 Replies
Gary
Gary4mo ago
@Bazze - unfortunately I don't have an answer for you here but I can tell you I have more trouble with this package (and really what it wraps around - the vue i18n) then I know what to do with. I have strugged with issue and after issue with it. I just keep jiggling the handle until I get it to work. I'm interested to see if anyone actually has an answer for you. You're in my prayers sir. 🙂
xibman
xibman4mo ago
GitHub
nuxt-zod-i18n/src/module.ts at main · xibman/nuxt-zod-i18n
Easily Translate Zod's error messages on nuxt. Contribute to xibman/nuxt-zod-i18n development by creating an account on GitHub.
xibman
xibman4mo ago
it use type from i18n without any problem but you need a recent version of nuxt/i18n
Bazze
Bazze4mo ago
According to my .lock the nuxtjs/i18n is resolved to 8.3.1, which is the latest version. At the moment the only import i have from nuxtjs/i18n is
import type { LocaleObject } from "@nuxtjs/i18n";
import type { DefineDateTimeFormat, DefineNumberFormat, } from "vue-i18n";

export interface LocaleConfig {
locale: LocaleObject;
datetimeFormats?: DefineDateTimeFormat;
numberFormats?: DefineNumberFormat;
}

export function defineLocale(locale: LocaleConfig): LocaleConfig {
return locale;
}
import type { LocaleObject } from "@nuxtjs/i18n";
import type { DefineDateTimeFormat, DefineNumberFormat, } from "vue-i18n";

export interface LocaleConfig {
locale: LocaleObject;
datetimeFormats?: DefineDateTimeFormat;
numberFormats?: DefineNumberFormat;
}

export function defineLocale(locale: LocaleConfig): LocaleConfig {
return locale;
}
What node version do you use to build nuxt-zod-i18n?
xibman
xibman4mo ago
still on 18 branch
Bazze
Bazze4mo ago
Tried building with bun instead a few times, but kept throwing the same error. Restarted vscode, and then it would build with yarn. Tried editing some things, the same error appeared. I then tried building with bun again and it would. A few times back and fourth. Thank you guys for your input. If i run into this or actually find the reason why ill post it. At the moment it seems like either the terminal or vscode is interfering with typescript. But i dont see how it would.
xibman
xibman4mo ago
you create a module like the one before or you are already in a nuxt app ?
Bazze
Bazze4mo ago
I created a standalone module.
xibman
xibman4mo ago
do you run the command dev:prepare ? do you use the template provided by nuxt ?
xibman
xibman4mo ago
GitHub
GitHub - nuxt/starter at module
Create a new Nuxt project, module, layer or start from a theme with our collection of starters. - GitHub - nuxt/starter at module
Bazze
Bazze4mo ago
At first i was using prepack, but jiti didnt play along so well with one of my exports, so i tried to prepack the module which is when i ran into the issue. Yes, it is the module template generated with nuxi
xibman
xibman4mo ago
okay for the zod module i use node / pnpm no problem with types
Bazze
Bazze4mo ago
Im using yarn for the workspaces in a monorepo with turborepo.
xibman
xibman4mo ago
if you have multiple version of nuxt-i18n installed the monorepo the problem can come from here
Bazze
Bazze4mo ago
It all seems to resolve to the latest in the yarn.lock
Want results from more Discord servers?
Add your server