Giter Site home page Giter Site logo

Comments (4)

bastienrossi avatar bastienrossi commented on August 15, 2024

Hi, the problem doesn't seem to come entirely from rollup, in fact rollup returns an object {__proto__: null, default: _sfc_main} instead of a module, so the defineAsyncComponent code doesn't work and doesn't call the .default

if (comp && (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  comp = comp.default
}

https://github.com/vuejs/core/blob/e0428884b57ac834274045bd33841263aeae259e/packages/runtime-core/src/apiAsyncComponent.ts#L100.

Workaround that I've found for the moment is to ask rollup to put the code in es2015.

defineNuxtConfig({
  vite: {
    $server: {
      build: {
        rollupOptions: {
          output: {
            generatedCode: {
              preset: 'es2015' // temporary fix for https://github.com/nuxt/nuxt/issues/27836
            }
          }
        }
      }
    }
  }
}

Generate

const BaseTestChild2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
	__proto__: null,
	default: _sfc_main
}, Symbol.toStringTag, { value: 'Module' }));

instead of

const BaseTestChild2 = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  default: _sfc_main
});

and match defineAsyncComponent condition.

from nuxt.js.

danielroe avatar danielroe commented on August 15, 2024

For a workaround, you can add an interop default line:

const BaseTestChild2 = defineAsyncComponent(
  () => import("@/components/BaseTestChild2.vue").then(r => r.default || r)
);

I don't think this is a Nuxt issue but rather a Vue one - defineAsyncComponent probably needs to update its condition. Would you raise an issue on vuejs/core#6638 ? 🙏

from nuxt.js.

bastienrossi avatar bastienrossi commented on August 15, 2024

There already seems to be a way out on view concerning the behaviour of "defineAsyncComponent".
vuejs/core#8351
It says that there is also another, cleaner alternative to converting everything to es2015 in rollup to fix the problem temporarily.

defineNuxtConfig({
  vite: {
    $server: {
      build: {
        rollupOptions: {
          output: {
            generatedCode: {
              symbols: true // temporary fix for https://github.com/nuxt/nuxt/issues/27836
            }
          }
        }
      }
    }
  }
}

from nuxt.js.

danielroe avatar danielroe commented on August 15, 2024

I would be willing to investigate adding that configuration in Nuxt by default.

from nuxt.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.