Combining Laravel + Vue.js I got Error: "Module not found: Error: Can't resolve './vue/app'"

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# Debugging the Dreaded Module Error: Combining Laravel and Vue.js Integrating frontend frameworks like Vue.js into a backend structure like Laravel is an incredibly powerful combination. However, setting up the asset bundling process—especially when dealing with module resolution errors during compilation—can often feel like navigating a maze of configuration files. If you are running into the error `"Module not found: Error: Can't resolve './vue/app'"` while trying to combine Laravel and Vue.js, you are hitting a very common snag related to how Webpack (or Vite, which powers modern Laravel setups) resolves file paths for ES Modules. As a senior developer, I can tell you that this error is almost never about the code itself; it’s almost always about the file system structure perceived by the bundler. Let's break down why this happens and how to fix it effectively. ## Understanding the Module Resolution Problem The error message `"Can't resolve './vue/app'"` indicates that when your main JavaScript file (`resources/js/app.js`) tries to import a module located at `./vue/app`, the module bundler (Webpack/Vite) cannot find a corresponding file or directory at that exact relative path. When dealing with Vue Single File Components (`.vue` files), the issue often lies in how you are attempting to import the component versus how the build system expects assets to be handled, especially when mixing traditional JavaScript module syntax (`import`) and older CommonJS syntax (`require`). ### The Likely Culprit: Asset Handling In your setup, where you have a file structure like `/resources/js/vue/app.vue`, the bundler needs explicit instructions on how to handle `.vue` files—they are not standard JavaScript modules that can be directly imported by default unless specific loaders or plugins are configured correctly for Single File Components (SFCs). Your approach of importing a file named `app` from a subdirectory often fails because the structure expects either direct file imports or asset handling via specific configuration. ## The Correct Approach: Fixing the Import Syntax The solution usually involves aligning your import statement with how Vue components are intended to be imported within a modern build system. Forget relying solely on relative paths for complex component structures; leverage the framework's built-in asset handling. Here is a conceptual breakdown of the correct way to structure and import Vue components in a Laravel/Vite environment: ### 1. File Structure Review Ensure your file structure is clean. If you are using Vite, assets should generally reside within `resources/js`. ``` resources/js/ ├── app.js <-- Your main entry point ├── main.js <-- Often the entry for Vue initialization └── vue/ └── App.vue <-- Your component file ``` ### 2. Correcting the Import in `app.js` Instead of trying to resolve the `.vue` file directly as a JavaScript module path for instantiation, you should ensure your main entry point initializes the Vue application correctly, typically importing the main entry file (`main.js`) which handles mounting. If you are using a setup where you want to import components individually (which is common in larger apps), you must ensure that the path resolution is correct *and* that the build configuration supports loading `.vue` files as components. **Example of a Robust Import:** In your main entry file (`resources/js/app.js`) or wherever you initialize Vue: ```javascript // If using ES Modules (recommended for modern setups) import { createApp } from 'vue'; import App from './vue/App.vue'; // Attempting to import the component directly const app = createApp(App); // ... rest of your initialization code app.mount('#app'); ``` **Crucial Note on Webpack/Vite Configuration:** For this line (`import App from './vue/App.vue'`) to work seamlessly, you must ensure that your `vite.config.js` (or `webpack.config.js` if using Laravel Mix) has the necessary Vue plugin configured to handle `.vue` file imports correctly. This configuration is often handled automatically by official Laravel scaffolding, but custom setups require explicit setup. ## Conclusion: Building a Solid Foundation Module resolution errors like `"Module not found"` are frustrating because they hide in the details of file paths rather than obvious syntax mistakes. In the world of modern full-stack development, mastering asset bundling and module resolution is key. Whether you are building complex applications on Laravel or leveraging frameworks like those detailed on [Laravel Company](https://laravelcompany.com), understanding the underlying build tools (Vite/Webpack) is essential for smooth development. By carefully checking your file paths, ensuring proper ES Module syntax, and verifying that your asset loaders are correctly configured, you can resolve these module errors and successfully combine Laravel’s robust backend with Vue.js’s dynamic frontend capabilities. Happy coding!