allow using vue runtime compiler in built nuxt app
See original GitHub issueEnvironment
Nuxt CLI v3.0.0-rc.1 11:41:57 RootDir: /home/jhuang/projets/nuxt3 11:41:59 Nuxt project info: 11:41:59
- Operating System:
Linux
- Node Version:
v16.13.1
- Nuxt Version:
3.0.0-rc.1
- Package Manager:
npm@8.3.0
- Builder:
vite
- User Config:
components
,hooks
- Runtime Modules:
-
- Build Modules:
-
Reproduction
app.vue
<template>
<div>
<Test />
</div>
</template>
<script>
import {defineNuxtComponent} from "#app";
import Test from "./components/test"
export default defineNuxtComponent({
components: {
Test
}
})
</script>
components/test.ts
import {defineNuxtComponent} from "#app";
export default defineNuxtComponent({
name: "TestCompile",
template: "<div>test</div>"
})
nuxt.config.ts
import {defineNuxtConfig} from 'nuxt'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
components: {
global: false
},
hooks: {
'vite:extendConfig': (config, {isClient, isServer}) => {
if(isClient)
config.resolve.alias.vue = 'vue/dist/vue.esm-bundler.js';
},
},
})
- run
npm run build
- run
npm run preview
- open http://0.0.0.0:3000/
- Error in console + server crash :
file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:9869
return (compileCache[cacheKey] = Function('require', code)(commonjsRequire));
^
TypeError: Cannot convert object to primitive value
at Function (<anonymous>)
at ssrCompile (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:9869:38)
at renderComponentSubTree (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:9960:30)
at renderComponentVNode (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:9946:16)
at Object.ssrRenderComponent (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:10361:12)
at _sfc_ssrRender (file:///home/jhuang/projets/nuxt3/.output/server/chunks/app/server.mjs:4048:32)
at renderComponentSubTree (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:10001:13)
at renderComponentVNode (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:9946:16)
at Object.ssrRenderComponent (file:///home/jhuang/projets/nuxt3/.output/server/chunks/index.mjs:10361:12)
at default (file:///home/jhuang/projets/nuxt3/.output/server/chunks/app/server.mjs:4022:42)
ERROR Command failed with exit code 1: node ./server/index.mjs 11:47:51
at makeError (node_modules/nuxi/dist/chunks/index5.mjs:1242:11)
at handlePromise (node_modules/nuxi/dist/chunks/index5.mjs:2071:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.invoke (node_modules/nuxi/dist/chunks/preview.mjs:224:5)
at async _main (node_modules/nuxi/dist/cli.mjs:46:20)
Describe the bug
I’m trying to use the template key in the component object of defineNuxtConfig to load components with dynamic templates. However the server seems to crash when it tries to compile the template server-side. It happens in production but not in dev.
seems like there’s a TODO remining in .output/server/chunks/index.mjs
at line 9841
function ssrCompile(template, instance) {
// TODO: This is copied from runtime-core/src/component.ts and should probably be refactored
const Component = instance.type;
const { isCustomElement, compilerOptions } = instance.appContext.config;
const { delimiters, compilerOptions: componentCompilerOptions } = Component;
const finalCompilerOptions = shared.extend(shared.extend({
isCustomElement,
delimiters
}, compilerOptions), componentCompilerOptions);
finalCompilerOptions.isCustomElement =
finalCompilerOptions.isCustomElement || shared.NO;
finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
const cacheKey = JSON.stringify({
template,
compilerOptions: finalCompilerOptions
}, (key, value) => {
return shared.isFunction(value) ? value.toString() : value;
});
const cached = compileCache[cacheKey];
if (cached) {
return cached;
}
finalCompilerOptions.onError = (err) => {
{
throw err;
}
};
const { code } = compilerSsr.compile(template, finalCompilerOptions);
return (compileCache[cacheKey] = Function('require', code)(commonjsRequire));
}
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:18 (10 by maintainers)
Top Results From Across the Web
use dynamic component in the nuxt layout get runtime compile ...
You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions ...
Read more >Compile Markdown as Vue template on Nuxt.js dynamically
For implementing data pipeline for the static website, I used to have Markdown files for content parts from long time ago. Probably starting...
Read more >The build Property - Nuxt
Nuxt lets you customize the webpack configuration for building your web application as you want.
Read more >Fix "[Vue warn]: You are using the runtime-only build of Vue"
With Vue CLI 3, in order for the Vue.js template compiler to be included in the build output, we need to set runtimeCompiler:...
Read more >Yarnpkg: where to set compilerOptions? - Get Help - Vue Forum
The compilerOptions config option is only respected when using a build of Vue.js that includes the runtime compiler (aka “full build”).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Hyperblaster yes i’ve ran into this issue too. I’ve managed to work around this by compiling the template into render function with compile() from the vue package. Instead of using template, prefer using compile
I have’nt figured out in what and why it does trigger this issue. It seems that in some cases, the ssrRender function compiled when using template does not prepend the _ssrInterpolate function parameters with _ctx.
@tkjaergaard this is my latest config for nuxt rc3, it should work for rc4 too. I think this can be refactored with the vueExternals option