question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue compile doesn't work properly in any case

See original GitHub issue

Environment

Nuxt CLI v3.0.0-27265876.3cd4494 19:48:54 RootDir: /home/projects/github-gjy9ju 19:48:56 Nuxt project info: 19:48:56


  • Operating System: Linux also tested with Darwin
  • Node Version: v14.19.0 also tested with v16.14.0
  • Nuxt Version: 3.0.0-27265876.3cd4494
  • Package Manager: npm@7.17.0 also tested with npm@8.3.1
  • Bundler: Vite
  • User Config: alias
  • Runtime Modules: -
  • Build Modules: -

Reproduction

pages/index.vue

<template>
  <div>
    <HtmlRenderer htmlText="<TestComponent :testProp='{a: `propA`, b: `propB` }' testString='test1' />" />
  </div>
</template>

components/HtmlRenderer.vue

<script lang="ts">
import { compile } from "vue";

export default defineComponent({
  props: {
    htmlText: {
      type: String,
      require: true,
      default: "",
    },
  },
  render() {
    return h(compile(this.htmlText));
  },
});
</script>

components/TestComponent.vue

<template>
  <div>
    <h1>{{ testString }}</h1>
    <slot />
    <h3>{{ testProp.a }} {{ testProp.b }}</h3>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  props: {
    testProp: Object,
    testString: String,
  },
});
</script>

Describe the bug

The proposed reproduction doesn’t work. Browser console throws a warning: Runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".


Adding an alias at nuxt.config.ts:

import { defineNuxtConfig } from 'nuxt3'
import { resolve } from "path";

export default defineNuxtConfig({
  alias: {
    vue: resolve(__dirname, "./node_modules/vue/dist/vue.esm-bundler.js"),
  }
})

VSCode terminal throws and error: Cannot start nuxt: Error: Cannot find module /node_modules/vue/dist/vue.cjs.js/server-renderer imported[...]


If I disable SSR at nuxt.config.ts with the alias:

import { defineNuxtConfig } from 'nuxt3'
import { resolve } from "path";

export default defineNuxtConfig({
  alias: {
    vue: resolve(__dirname, "./node_modules/vue/dist/vue.esm-bundler.js"),
  },
  ssr: false
})

Browser console throws another warning: Failed to resolve component: TestComponent

If I take an old version of nuxt 3 (like nuxt3@3.0.0-27417464.ad52b79) the last option works perfectly.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
shawncampcommented, Nov 22, 2022

@abdonrd I do have the TS error. I’ve had to ignore it.

I’ll test on my end without the other entries. Thank you.

1reaction
korgan00commented, Apr 11, 2022

@korgan00 This worked for me.

import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig({

  hooks: {
    'vite:extendConfig': (config, { isClient, isServer }) => {
      if (isClient)
        config.resolve.alias.vue = 'vue/dist/vue.esm-bundler'
    },
  },

})

Thank you! I also needed to use components.global = true. Now it is working. I provide the nuxt.config.ts solution.

import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
  components: {
    global: true,
    dirs: ['~/components']
  },
  hooks: {
    'vite:extendConfig': (config, { isClient, isServer }) => {
      if (isClient)
        config.resolve.alias.vue = 'vue/dist/vue.esm-bundler.js'
    },
  },
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue-cli compiled app not initializing in certain cases
Each app is compiled as an single app-build. Those apps have been working, but sometime ago I faced really strange issue where one...
Read more >
How to build your first Vue.js component - freeCodeCamp
But in our case, since we're passing numbers and booleans, it's important we do. The props and data properties are merged at compile...
Read more >
Frequently asked questions — Vuetify
Why is Search Vuetify not working properly? My application won't compile due to sass / scss errors. Are there examples on how the...
Read more >
Render Functions & JSX | Vue.js
This avoids unintended breakage in case the internal properties are changed. ... If a render function component doesn't need any instance state, ...
Read more >
Vue 3 Tutorial (for Vue 2 Users) - Vue.js Developers
If you try this, you'll see that it doesn't work. The issue is that scoped styling is determined at compile time when the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found