search

Home  >  Q&A  >  body text

Vue 3 - "Unable to resolve component" warning

<p>I encountered this warning when trying to import a component from my index.js file. </p> <p>This is my components folder: </p> <pre class="brush:php;toolbar:false;">components/ |-- index.js |-- ComponentA.vue |-- ComponentB.vue |-- ComponentC.vue</pre> <p> and index.js: </p> <pre class="brush:php;toolbar:false;">import ComponentA from './ComponentA'; import ComponentB from './ComponentB'; import ComponentC from './ComponentC'; export { ComponentA, ComponentB, ComponentC };</pre> <p>When I try this in any component (B or C)</p> <pre class="brush:php;toolbar:false;"><script> import { ComponentA } from './'; console.log(ComponentA); // undefined export default { components: {ComponentA} } </script></pre> <p>I get a warning in the console, how do I fix it? What am I doing wrong here? </p> <p>By the way, this method works:</p> <pre class="brush:php;toolbar:false;">import ComponentA from './ComponentA';</pre> <p>But I don't want to use this method because I have many components in <code>components</code> folder</p>
P粉451614834P粉451614834464 days ago454

reply all(1)I'll reply

  • P粉600845163

    P粉6008451632023-08-27 09:46:33

    You should write the import statement in the following form:

    <script>
    import { ComponentA } from './components';
    
    export default {
        components: { ComponentA }
    }
    </script>

    reply
    0
  • Cancelreply