Skip to content

Relative imports inside locale .js are converted to incorrect deep relative paths in .nuxt build #3890

@NirvanaCh7

Description

@NirvanaCh7

Environment

Reproduction

NirvanaCh7/nuxt-i18n-issue-20251203
It’s easy to describe, you don’t need it.

Describe the bug

i18n/locales/en/index.js

import common from './common.js'

export default {
    ...common,
}

i18n/locales/en/common.js

export default { welcome: 'Welcome',}

.nuxt/dev/index.mjs

import common from '../../../../../../../../../i18n/locales/en/common.js';
// 9 "../"

result:

Cannot find module '/i18n/locales/en/common.js' imported from index.mjs

I could access it using an ~~ alias, that’s not a problem. I’m trying to figure out why this happens. Maybe it’s an issue of Nuxt?

Additional context

New issue
i18n/locales/en/index.js

import common from '~~/i18n/locales/en/common.js'

export default {
    ...common,
}

i18n/locales/en/common.js

// fails×  import another from '~~/i18n/locales/en/another.js'
//Cannot find package '~~' imported from
import another from './another.js' // works√
export default {
 welcome: 'Welcome',
...another
}

Maybe I am using it incorrectly.

And I found that this part ,after the first-level import, is pre-compiled, and refreshing the browser does not apply changes. It seems the file is not included in Nuxt’s HMR watch list.

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions