Create an error in Vue.js for a component that doesn't exist.
P粉765570115
2023-08-03 17:43:26
<p>When we try to use a component that doesn't exist, I want an error to be generated instead of a simple warning in the console: </p>
<pre class="brush:php;toolbar:false;">[Vue warn]: Failed to resolve component: nonexisting-component
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
at <MainLayout onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
at <RouterView>
at <App></pre>
<p>Sometimes people break the flow, but they may not notice because the component doesn't show up at all. Is there any way to solve this problem? </p>
It is very easy to solve this problem using the Rollup plugin. Plug-ins can be written directly in vite.config.js. Here you can use rollup's resolveId hook. Vite/Rollup calls this hook when it cannot resolve an import. If it's a Vue Single File Component (SFC) you can resolve it to any placeholder component of your choice:
Translate src/components/Placeholder.vue (if you want it to be empty, just do this):