export 'default' (imported as 'Vue') was not found in 'vue' in Vue 3 and Laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Resolving the Export Nightmare: Dealing with 'default' in Vue 3 and Laravel Applications

As a senior developer working on hybrid frameworks like Laravel and Vue, we often encounter subtle but frustrating errors during setup, especially when bridging older conventions with newer framework versions. The specific error you are facing—export 'default' (imported as 'Vue') was not found in 'vue'—is a classic symptom of module interoperability issues that arise when transitioning between how Vue is imported and how the build system handles ES Modules, particularly within complex setups like those used for Laravel applications.

This post will diagnose why this error occurs in your specific setup and provide practical, modern solutions to ensure your Vue 3 application compiles smoothly alongside your backend framework.


The Root Cause: Module System Evolution in Vue

The issue stems from the evolution of how Vue exposes its components and core library via ES Modules (ESM). In older Vue setups or when mixing module systems, the expectation for importing the core library (import Vue from 'vue') might conflict with the way Single File Components (SFCs) are exported.

In Vue 3, while the core runtime is designed to be more modular, legacy build tools (like Webpack/Mix configurations often used in Laravel setups) sometimes struggle to correctly resolve the default export from component files (.vue files) when attempting to register them globally using methods like Vue.component(). The error indicates that the module resolution mechanism cannot find a default export named Vue within the installed vue package, suggesting a mismatch between the runtime import and the component import mechanism.

Diagnosing Your Setup: Component Imports vs. Runtime Imports

Let's look at the specific parts of your configuration to understand where the conflict lies:

  1. Runtime Import (app.js):

    javascript
    window.Vue = require('vue'); // This imports the runtime library successfully.
    // ...
    const app = new Vue({ el: '#app' });

    This part correctly loads the Vue runtime, but it doesn't fix the component loading error.

  2. Component Registration (index.js):

    javascript
    import Vue from 'vue'; // Imports the core library object
    // ...
    Vue.component('example-component', require('./components/ExampleComponent.vue').default); // Error occurs here

    The problem lies in require('./components/ExampleComponent.vue').default. While this is the standard way to access default exports in CommonJS environments, modern build pipelines often prefer using ES Module imports (import) for better tree-shaking and compatibility with Vite/Webpack configurations used by Laravel projects.

The Solution: Adopting Modern ES Module Imports

The most robust solution is to refactor your component loading mechanism to strictly adhere to ES Module standards, which aligns perfectly with modern Vue 3 development practices and provides cleaner integration within the broader Laravel ecosystem.

Instead of relying solely on require() and accessing .default, we should leverage standard ES import syntax in our entry points. This approach is generally safer and resolves these module resolution conflicts immediately.

Refactored Example for Component Loading

We will modify how components are imported to ensure the build process correctly extracts the component definition:

In ./js/app.js (Refactored):

javascript
require('./bootstrap');

// Import Vue directly using ES Module syntax if possible, or rely on module resolution
import Vue from 'vue'; 
import './components'; // This will now handle the component registration cleanly

// Assuming components are registered within ./components/index.js via standard imports
// The manual registration might be simplified or moved to a centralized setup file for cleaner builds.

const app = new Vue({
    el: '#app'
});

In ./js/components/index.js (Refactored):

Instead of manually iterating and using Vue.component(), we can ensure the component registration happens during module loading, which is often cleaner for build tools. For a simpler approach that addresses your specific error:

javascript
import Vue from 'vue';
import Card from './Card.vue'; // Import as ES Module
import Button from './Button.vue'; // Import as ES Module

// Registering components cleanly using the imported modules
Vue.component('Card', Card);
Vue.component('Button', Button);

// If you still need global component registration logic, ensure it's handled post-initialization 
// or within a dedicated setup file to avoid interference with module bundling.

By shifting from deep require() calls on .vue files to using standard ES import statements for components, you allow the underlying bundler (like Webpack, often configured via Laravel Mix) to correctly handle the default export resolution, eliminating the "export 'default' was not found" error. This modern approach ensures your Vue code remains compatible with best practices, making complex full-stack development significantly smoother, much like building robust features within a Laravel application.

Conclusion

Encountering module errors in hybrid setups is inevitable when mixing established backend frameworks with rapidly evolving frontend libraries. The key takeaway here is to prioritize modern ES Module syntax (import/export) over legacy CommonJS require() when dealing with Vue 3 components. By adopting these practices, you ensure that your build pipeline correctly interprets the component structure, leading to a stable and maintainable development experience for your Laravel/Vue projects.