In my project with Vue 2.7 and webpack4 for SSR, I encountered an error message stating:
render function or template not defined in component: anonymous
. This issue arises under the following circumstances:
- When using a child component.
<template>
...
</template>
<script>
import componentA from '. /componentA''
export default {
...
component: {componentA},
}
<script>
- Importing from external files (both named export and default export).
Default Export:
const somethingFunc = () => {}
export default somethingFunc
Named Export:
export const somethingFunc = () => {}
Vue Component File:
<template>
...
</template>
<script>
import somethingFunc from '... /external.js'
export default {
...
computed: {
something() {
return somethingFunc()
}
}
}
}
</script>
- Using mixins imported with named export.
export const Mixin = {
props: {...} ,
methods: {...}
}
This is the list of dependencies stated in package.json:
"dependencies": {
"axios": "^0.21.4",
"clean-webpack-plugin": "^4.0.0",
"core-js": "^3.7.0",
"deepmerge": "^4.2.2",
"express": "^4.17.1",
"knex": "^2.4.0",
"lodash": "^4.17.20",
"lozad": "^1.16.0",
"lru-cache": "^7.14.1",
"md5": "^2.3.0",
"moment": "^2.29.1",
"numeral": "^2.0.6",
"pg": "^8.8.0",
"serve-favicon": "^2.5.0",
"vue": "^2.7.14",
"vue-server-renderer": "^2.7.14"
},
"devDependencies": {
...
}
I have searched for similar errors but could not find any solutions. Any insights on this issue would be greatly appreciated. It's worth noting that without these conditions, the rendering works correctly.