Skip to content
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

Cannot create property 'locales' on string '[object Object]' #3365

Open
dennisgeerts opened this issue Feb 21, 2025 · 3 comments
Open

Cannot create property 'locales' on string '[object Object]' #3365

dennisgeerts opened this issue Feb 21, 2025 · 3 comments

Comments

@dennisgeerts
Copy link

dennisgeerts commented Feb 21, 2025

Environment

  • Node Version: v22.14.0
  • Nuxt Version: 3.15.4
  • Nitro Version: 2.10.4
  • Package Manager: yarn 1.22.22
  • Runtime Modules: @nuxtjs/[email protected]

Reproduction

I could not create a stackblitz that reproduced this error.

i18n: {
    defaultLocale: 'nl-be',
    locales: [
      { code: 'nl-be', name: 'Nederlands (België)', shortName: 'nl', file: 'nl-be.js', dir: 'ltr' },
      { code: 'fr-be', name: 'Français (Belgique)', shortName: 'fr', file: 'fr-be.js', dir: 'ltr' },
      { code: 'en-be', name: 'English (Belgium)', shortName: 'en', file: 'en-be.js', dir: 'ltr' },
    ],
    strategy: 'prefix',
    lazy: true,
    vueI18n: './i18n.config.js',
  },

The i18n.config.js file is in the same root folder as nuxt.config.js:

export default {
  datetimeFormats: {
    'en-be': {
      short: { year: 'numeric', month: 'short', day: 'numeric' },
    },
    'nl-be': {
      short: { year: 'numeric', month: 'short', day: 'numeric' },
    },
    'fr-be': {
      short: { year: 'numeric', month: 'short', day: 'numeric' },
    },
  },
};

The language files are in i18n/locales/nl-be.js, i18n/locales/fr-be.js, i18n/locales/en-be.js. And contain this:

export default defineI18nLocale(async (locale) => {
  return {
    welcome: 'Welkom, Welkom!',
  };
});

Describe the bug

When starting Nuxt i receive the error :
ERROR Cannot start nuxt: Cannot create property 'locales' on string '[object Object]'

I am sure this is related to @nuxtjs/i18n, because if i comment it out in the nuxt.config.js modules, the error disappears and my nuxt application runs.

I tried reducing the sample code above to the absolute minimum but the same error remains.

Additional context

No response

Logs

This is the full stack trace: 

 ERROR  Cannot start nuxt:  Cannot create property 'locales' on string '[object Object]'                                                                                          nuxi  08:11:57  

    at prepareRuntime (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxtjs/i18n/dist/module.mjs:1995:50)
    at setup (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxtjs/i18n/dist/module.mjs:2234:5)
    at async normalizedModule (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/kit/dist/index.mjs:2149:17)
    at async installModule (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/kit/dist/index.mjs:2427:95)
    at async initNuxt (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/nuxt/dist/shared/nuxt.CrJjphBv.mjs:5339:5)
    at async NuxtDevServer._load (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/cli/dist/chunks/dev2.mjs:162:5)
    at async NuxtDevServer.load (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/cli/dist/chunks/dev2.mjs:94:7)
    at async NuxtDevServer.init (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/cli/dist/chunks/dev2.mjs:89:5)
    at async Object.run (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/@nuxt/cli/dist/chunks/dev-child.mjs:83:5)
    at async runCommand (/C:/Users/dennis/Documents/gad/Projects/gad/frontend/node_modules/citty/dist/index.mjs:316:16)
@BobbieGoede
Copy link
Collaborator

I could not create a stackblitz that reproduced this error.

This might be related to using yarn as package manager, there have been a few strange issues exclusive to it recently. A repo with the minimal reproduction would be very helpful to debug this 🙏

The i18n.config.js file is in the same root folder as nuxt.config.js:

This file should be to be in the i18n directory too

@dennisgeerts
Copy link
Author

dennisgeerts commented Feb 21, 2025

Thanks for your fast reply.
Setting the i18n.config.js file in the i18n folder still gives me the same error, but I missed've missed that from the docs that it belongs there, thanks for the headsup!

I tried transforming the stackblitz from npm to yarn : https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-3fvgnmxg
but i'm not sure if i did it correctly actually.

update: in my own solution i changed everything from Yarn to NPM, but the exact same error still occurs.

@BobbieGoede
Copy link
Collaborator

I'm unable to reproduce the issue with that project, I did have to install typescript as a dependency can you give that try?

The module needs to have some additional checks whether typescript is being used or not, currently it relies on typescript whether it is being used or not, to support loading ts files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants