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

ssr does not properly handle dynamic import correctly in onMounted #8571

Closed
issue-up bot opened this issue Jun 13, 2022 · 3 comments · Fixed by #8641
Closed

ssr does not properly handle dynamic import correctly in onMounted #8571

issue-up bot opened this issue Jun 13, 2022 · 3 comments · Fixed by #8641

Comments

@issue-up
Copy link

issue-up bot commented Jun 13, 2022

   Forwarded from downstream issue:


Environment

Nuxt project info: 14:31:07


  • Operating System: Darwin
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.1-27510703.46ecbc5
  • Package Manager: pnpm@6.32.9
  • Builder: vite
  • User Config: target
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-jvkzzr?file=package.json

run yarn generate in Terminal

Describe the bug

build in server side, when use import() in lifecycle hook, show error window is not defined

i check in .nuxt/dist/server/server.mjs, found import() result at toplevel , like this :

const entry$1 = (ctx) => entry(ctx);
window.test = 123;      //  this is my import result
const test = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null
}, Symbol.toStringTag, { value: "Module" }));

Additional context

No response

Logs

No response

@danielroe
Copy link
Contributor

This probably should not be opened as-is. I need to look into this a bit more to create a reproduction.

@danielroe
Copy link
Contributor

Here's a reproduction. Default rollup behaviour is to render dynamic chunks.

@sapphi-red
Copy link
Member

sapphi-red commented Jun 17, 2022

Dynamic imported modules are inlined because Vite turns inlineDynamicImports on for SSR builds. (related: nuxt/nuxt#14846)

Changing the config to below worked for the nuxt reproduction.

export default defineNuxtConfig({
  target: 'static',
  vite: {
    build: {
      rollupOptions: {
        output: {
          inlineDynamicImports: false
        },
      },
    }
  }
});

I think turning inlineDynamicImports off for ssr.target = 'node' by default makes sense. I assume this option was turned on for ssr.target = 'webworker'.

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

Successfully merging a pull request may close this issue.

3 participants