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

Not work SPA (ssr: false) #2029

Closed
apss-pohl opened this issue Apr 28, 2023 · 34 comments · Fixed by #2025, #2099 or #2199
Closed

Not work SPA (ssr: false) #2029

apss-pohl opened this issue Apr 28, 2023 · 34 comments · Fixed by #2025, #2099 or #2199
Assignees
Labels
config ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8

Comments

@apss-pohl
Copy link

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.4.2
  • Nitro Version: 2.3.3
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: srcDir, ssr, typescript, hooks, build, css, vite, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.11
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-xhfdq1-de15an

Describe the bug

Run "yarn build".
Then browse to ".nuxt/dist/client/_nuxt/i18n.options.*.js". It's content will look like this:

import { _ as r, s as index } from './entry.075876a4.js';
async function _(n) {
  const e = await r(() => import('./i18n.config.15578b8d.js'), [], import.meta.url).then(
      (t) => t.default || t,
    ),
    a = index.isFunction(e) ? await e(n) : index.isObject(e) ? e : {};
  {
    let t = null;
    try {
      const o = '/i18n-config-5fcc7ca7.js';   // <---------------------------- This file is not created
      t = await r(() => import(o), [], import.meta.url).then((s) => s.default || s);
    } catch (error) {
      console.error(format(error.message));
    }

    return (a.messages = t || {}), a;
  }
}

export { _ as default };

Imported file " '/i18n-config-5fcc7ca7.js';" (with the dashes) is not created at all, therefore it breaks.

Additional context

I already opened a issue in the nuxt tracker (nuxt/nuxt#20518) but now i am wondering if it is rather related to the module. If not it can be closed here.

Logs

No response

@apss-pohl
Copy link
Author

This was introduced since beta.11

@StefanVDWeide
Copy link

I'm running into the same issue. Have you maybe found a workaround for now?

@kazupon kazupon added v8 and removed pending triage labels May 1, 2023 — with Volta.net
@kazupon kazupon self-assigned this May 1, 2023
@kazupon kazupon added the ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf label May 1, 2023 — with Volta.net
@apss-pohl
Copy link
Author

I'm running into the same issue. Have you maybe found a workaround for now?

For now i reverted to "8.0.0-beta.10-28003311.2c39470""

@kazupon kazupon reopened this May 8, 2023
Copy link
Collaborator

kazupon commented May 8, 2023

I've fixed this issue.
Please check edge channel 8.0.0-beta.11-28059008.d1499b6 version.
Thanks!

@apss-pohl
Copy link
Author

I got a different error now:

@aps-services/render:build:  ERROR  Plugin error - Unable to get file name for unknown file "381c911f".
@aps-services/render:build: 
@aps-services/render:build:   at error (/mnt/share/dev/code/poc-ts-boilerplate/node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
@aps-services/render:build:   at Object.FileEmitter.getFileName (/mnt/share/dev/code/poc-ts-boilerplate/node_modules/rollup/dist/es/shared/node-entry.js:24128:24)
@aps-services/render:build:   at /mnt/share/dev/code/poc-ts-boilerplate/node_modules/@nuxtjs/i18n/dist/module.mjs:1216:50
@aps-services/render:build:   at Array.reduce (<anonymous>)
@aps-services/render:build:   at Object.generateBundle (/mnt/share/dev/code/poc-ts-boilerplate/node_modules/@nuxtjs/i18n/dist/module.mjs:1215:44)
@aps-services/render:build:   at /mnt/share/dev/code/poc-ts-boilerplate/node_modules/rollup/dist/es/shared/node-entry.js:24551:40
@aps-services/render:build:   at processTicksAndRejections (node:internal/process/task_queues:96:5)
@aps-services/render:build: 
@aps-services/render:build: ERROR: command finished with error: command (/mnt/share/dev/code/poc-ts-boilerplate/apps/render) yarn run build exited (1)

Copy link
Collaborator

kazupon commented May 9, 2023

hmm 🤔
when we are set ssr: false on nuxt.config.ts, we can meet your error.

@apss-pohl
Copy link
Author

hmm
when we are set ssr: false on nuxt.config.ts, we can meet your error.

I can confirm, also useing "ssr:false" in my project.

@kazupon kazupon added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage and removed ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf labels May 16, 2023 — with Volta.net
@darthf1
Copy link

darthf1 commented May 17, 2023

I'm in the same boat:

#0 65.62  ERROR  Plugin error - Unable to get file name for unknown file "10d04b9c".
#0 65.62 
#0 65.62   at error (node_modules/rollup/dist/es/shared/node-entry.js:2125:30)
#0 65.62   at FileEmitter.getFileName (node_modules/rollup/dist/es/shared/node-entry.js:24169:24)
#0 65.62   at node_modules/@nuxtjs/i18n/dist/module.mjs:1216:50
#0 65.62   at Array.reduce (<anonymous>)
#0 65.62   at Object.generateBundle (node_modules/@nuxtjs/i18n/dist/module.mjs:1215:44)
#0 65.62   at node_modules/rollup/dist/es/shared/node-entry.js:24592:40
#0 65.62   at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
#0 65.62 
#0 65.73  ELIFECYCLE  Command failed with exit code 1.

Downgrading from beta-12 to beta-11 and adding the following to the package.json resolved it for me:

  "pnpm": {
    "overrides": {
      "@nuxt/kit": "$nuxt",
      "@nuxt/schema": "$nuxt"
    }
  }

I'm on Nuxt 3.4.3, but @nuxt/kit and @nuxt/schema were updated to 3.5.0.

@gbyesiltas
Copy link

Same here ✋ nuxt 3.5.0 ssr:false, beta-12

Downgrading to beta-11 fixes it for me as well

@kazupon kazupon changed the title SSG with i18n missing import Not work SPA (ssr: false) May 18, 2023
@kazupon kazupon added ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf config and removed 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels May 18, 2023 — with Volta.net
PikachuEXE added a commit to PikaSer-Cosmos/pikaser-website-main that referenced this issue May 23, 2023
kazupon added a commit that referenced this issue May 23, 2023
kazupon added a commit that referenced this issue May 23, 2023
@stockholmz
Copy link

@kazupon I can confirm that the recent #2099 fixed my teams production build on Netlify! Great work.

@gunter423
Copy link

Ah yes @stockholmz , I had not seen, the PR is very recent, thanks !

@apss-pohl
Copy link
Author

I am having a different error now:

image

@gbyesiltas
Copy link

gbyesiltas commented May 26, 2023

@kazupon thank you for your effort. I appreciate it. Unfortunately, it still throws error. This time different error on compile time

For me the working combo was:
1- Update to @nuxtjs/i18n-edge (I had to also delete package-lock)
2- Add "type": "module" to package.json
3- Did not use i18n.config.ts as the config file name. Rather used nuxt.i18n.config.ts but the exact name doesn't matter. I did it to avoid auto-importing of the configuration
4- On nuxt.config.ts used the object way of providing module options instead of the array syntax:

// causes errors
modules: [["@nuxtjs/i18n", i18nConfig]],

// works
modules: ["@nuxtjs/i18n"],
i18n: i18nConfig,

@serdarde
Copy link

thanks to gbyesiltas I could also solve the problem, but I had to make a small change. Installing the @nuxtjs/i18n-edge isn't enough, you should also register it as module.

So this is wrong (for now):
modules: [["@nuxtjs/i18n", i18nConfig]],

Instead do this:
modules: ['@nuxtjs/i18n-edge'],

and put your config like this:

  i18n: {
    vueI18n: './i18n.config.ts'
  },

I think this will be unnecessary after bug fix goes in to the next (main) branch.

@CavalcanteLeo
Copy link

CavalcanteLeo commented May 30, 2023

that didn't work for me @serdarde =(

@SimonSimCity
Copy link

SimonSimCity commented May 30, 2023

Not sure if this is the right issue ... I'm getting an error like the one reported in #2077 but I cannot see the import e82347ba stated as missing in the error message ( ERROR [nuxtjs:i18n-resource-dynamic] Plugin error - Unable to get file name for unknown file "e82347ba".) being used anywhere in the code, so I don't know if I'm right when adding my story here...

When I try following this procedure here, and I get somewhere closer to the goal. When replacing @nuxtjs/i18n version 8.0.0-beta.12 by @nuxtjs/i18n-edge version 8.0.0-beta.12-28090693.c8406ad, I'm faced with a new error when trying to build:

 ERROR  (node:52982) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.                        5:47:04 PM
(Use node --trace-warnings ... to show where the warning was created)


 ERROR  [nuxt] [request error] [unhandled] [500] Unexpected token 'export'                                                                     5:47:04 PM
  at internalCompileFunction (node:internal/vm:73:18)  
  at wrapSafe (node:internal/modules/cjs/loader:1149:20)  
  at Module._compile (node:internal/modules/cjs/loader:1190:27)  
  at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)  
  at Module.load (node:internal/modules/cjs/loader:1089:32)  
  at Module._load (node:internal/modules/cjs/loader:930:12)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)  
  at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

  ├─ /__i18n__/prerender/46b58757.js (111ms) (Error: [500] )                                                                             nitro 5:47:04 PM

[5:47:04 PM]  WARN  HTML content not prerendered because ssr: false was set. You can read more in https://nuxt.com/docs/getting-started/deployment#static-hosting.

I've tried to set it (which requires my prettier config to be renamed to prettier.config.cjs) and it works 😃 🎉 , but I'd like to avoid having to set "type": "module" in my package.json file. 😅

EDIT: Renaming the config file was not required - it works for me having the config file named i18n.config.ts.

@SimonSimCity
Copy link

Just found out that adding "type": "module" now is required to use this package 😊 #2052 - so it's working for me 😎👍🎉

@CavalcanteLeo
Copy link

Just found out that adding "type": "module" now is required to use this package 😊 #2052 - so it's working for me 😎👍🎉

Mine was already with type module, and it does not work

@steinerd
Copy link

steinerd commented Jun 1, 2023

Something in the vicinity of

if (process.dev || (process.server && process.env.prerender)) {
is fishy...

I'm looking at the mjs module in the node_modules and it's coming over like this...

const baseDir = dirname$1(query.from);
          const code = `import { precompileMessages, formatMessage } from '#build/${NUXT_I18N_TEMPLATE_INTERNAL_KEY}'
import { isSSG } from '#build/${NUXT_I18N_TEMPLATE_OPTIONS_KEY}'
import { isObject, isFunction } from '@intlify/shared'
export default async function(context) {
  const loader = await import(${JSON.stringify(`${resolve$1(baseDir, query.target)}?config=true`)}).then(m => m.default || m)
  const config = isFunction(loader)
    ? await loader(context)
    : isObject(loader)
      ? loader
      : {}
  __DEBUG__ && console.log('loadConfig', config)
  if (process.dev || process.server || !isSSG) {
    config.messages = await precompileMessages(config.messages, ${JSON.stringify(query.c)})
    return config
  } else {
    __DEBUG__ && console.log('already pre-compiled vue-i18n messages')
    let messages = null
    try {
      const key = \`/i18n-config-${query.c}.js\` 
      messages = await import(/* @vite-ignore */ key /* webpackChunkName: nuxt-i18n-config-${query.c} */).then(
        m => m.default || m
      )
    } catch (e) {
      console.error(format(e.message))
    }
    config.messages = messages || {}
    return config
  }
}`;

Which if you'll see if (process.dev || process.server || !isSSG) doesn't match the code currently in the next branch.

I've updated my package.json to use the edge version and I'm still seeing this.

{
  ...
    "devDependencies": {
        ...,
       "nuxtjs/i18n": "npm:@nuxtjs/i18n-edge",
        ...,
    }
  ...
}

In short, this "unplugin" routine needs to also check to see if nuxt is set for SSR, and to not look for a pre-render config in the event that happens.

@Toma-iwit
Copy link

@gbyesiltas answer works for me

@uke5tar
Copy link

uke5tar commented Jun 11, 2023

Thanks @gbyesiltas
I resolved it like this except for that I didn't need to rename i18.config.ts.
Small hint: this is how to upgrade to i18n edge. Change this line in package.json and run npm i again.

"@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge",

@apss-pohl
Copy link
Author

Just updated to: "@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge@8.0.0-beta.12-28104842.5ed73d5",

Still get
image

@jekuer
Copy link

jekuer commented Jun 12, 2023

@apss-pohl , you read the discussion above? There is no officially released fix yet (unfortunately).

@apss-pohl
Copy link
Author

I was reading that the issue was resolved for some users and there was a new release, that why i gave it a try. But i`ll be patient and keep testing.

@Archetipo95
Copy link

I don't know if this issue is related to my problem. While building on Netlify i got this error after updating i18n to beta 12 from beta 10: [log] [nitro] ├─ /__i18n__/prerender/9bec0e7d.js (396ms) (Error: [500] )

@aburii
Copy link

aburii commented Jun 15, 2023

Does putting the package version in edge is a kind of downgrade ? I applied this solution (edge) to solve my build and it worked for me (after rolling my head on the keyboard for an hour). What are the pros and cons ?

@ainajh
Copy link

ainajh commented Jun 15, 2023

@aburii Can you help me but I also have a problem when I followed what you said. I tried to run "nuxt generate" command and here is my error
image
image

Copy link
Collaborator

kazupon commented Jun 16, 2023

related issue
#2156

When the same locale file (.js or .ts) as common logics on langDir option, nuxt i18n module doesn’t work for ssr: false.
it's acknowledged that there is a bug.

@ainajh
Copy link

ainajh commented Jun 16, 2023

Thanks @gbyesiltas
I deleted the "package.lock.json" or "yarn.lock" file and redid a "yarn install".
I used @nuxtjs/i18n-edge and added "type": "module" in package.json. Great work.
image
I think it can help others too

@terwer
Copy link

terwer commented Jun 16, 2023

Same here nuxt 3.5.2 ssr:false, beta-12

@terwer
Copy link

terwer commented Jun 16, 2023

1 set package.json

"type": "module",

2 install @nuxtjs/i18n-edge

pnpm add @nuxtjs/i18n-edge -D

3 and change nuxt.config.ts to

modules: ["@nuxtjs/i18n-edge"]

works for me.

nuxt 3.5.2 ssr:false, beta-12

@valentiniljaz
Copy link

After many hours of trying different combinations this one worked for me:

  1. Install latest beta version 8.0.0-beta.12-28113576.7bc33c3
"devDependencies": {
    ...
    "@nuxtjs/i18n-edge": "8.0.0-beta.12-28113576.7bc33c3",
    ...
}
  1. Set module in nuxt.config.ts
modules: [
        ....
        '@nuxtjs/i18n-edge',
        ....
]
  1. Rename i18n.config.ts to nuxt.i18n.config.ts

Works for:

  • nuxt 3.5.3
  • nitro 2.4.1
  • ssr: false
  • i18n: 8.0.0-beta.12-28113576.7bc33c3

@0fatihyildiz
Copy link

Thanks @gbyesiltas I deleted the "package.lock.json" or "yarn.lock" file and redid a "yarn install". I used @nuxtjs/i18n-edge and added "type": "module" in package.json. Great work. image I think it can help others too

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8
Projects
None yet