#Using nuxtjs/i18n types in a module

1 messages · Page 1 of 1 (latest)

clever flare
#

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";

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)

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'

...
worldly lance
#

@clever flare - 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. 🙂

grizzled anchor
#

it use type from i18n without any problem

#

but you need a recent version of nuxt/i18n

clever flare
#

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;
}
#

What node version do you use to build nuxt-zod-i18n?

grizzled anchor
#

still on 18 branch

clever flare
#

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.

grizzled anchor
#

you create a module like the one before

#

or you are already in a nuxt app ?

clever flare
#

I created a standalone module.

grizzled anchor
#

do you run the command dev:prepare ?

#

do you use the template provided by nuxt ?

clever flare
#

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

grizzled anchor
#

okay

#

for the zod module i use node / pnpm

#

no problem with types

clever flare
#

Im using yarn for the workspaces in a monorepo with turborepo.

grizzled anchor
#

if you have multiple version of nuxt-i18n installed the monorepo the problem can come from here

clever flare
#

It all seems to resolve to the latest in the yarn.lock