Laravel 8 (Inertia js) - Getting Vue error 'app.js:30559 [Vue warn]: Error in created hook: "Error: Cannot find module...'

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Laravel 8 (Inertia.js) - Solving the Vue Module Error in Inertia Applications

Setting up a modern stack like Laravel with Inertia.js and Vue provides a powerful way to build dynamic, single-page applications within the familiar Laravel ecosystem. However, when dealing with module resolution—especially when dynamically loading components via routes—developers often run into tricky errors related to file paths.

This post addresses a very specific and frustrating error: [Vue warn]: Error in created hook: "Error: Cannot find module './Test'". We will dissect why this happens in an Inertia setup and provide the robust solution you need to keep building with Laravel.

Understanding the Inertia Module Resolution Issue

You have correctly identified the core problem: when your route calls Inertia\Inertia::render('Test'), the underlying mechanism tries to resolve 'Test' into a Vue component file (./Pages/Test.vue). The error indicates that the JavaScript runtime (specifically the require() call within your main app.js entry point) cannot find the module it is looking for.

In Inertia applications, this usually points to a mismatch between how the server-side routing logic expects the file path and how the client-side bundling system resolves those paths during the build process.

The Setup Context

Let's review your structure:

  • Route: Route::get('/test', function() { return Inertia\Inertia::render('Test'); });
  • File Location: resources/js/Pages/Test.vue

The error occurs here in your main entry file (app.js):

resolveComponent: (name) => require(`./Pages/${name}`).default, // Fails when name is 'Test'

The dynamic use of Node's require() for file loading within a bundled environment can be brittle if the pathing isn't perfectly aligned with the compiled output structure.

The Solution: Ensuring Correct Module Pathing

While the symptom points to a file not being found, the fix often involves ensuring that the imported path is resolved correctly relative to the entry point or by moving towards a more explicit import strategy that modern bundlers prefer.

For Inertia applications built on Laravel, the most reliable solution is to ensure your component resolution logic accurately mirrors the structure used by Vite/Webpack when bundling assets.

Step 1: Verify File Structure (The Foundation)

First and foremost, double-check your directory structure. The path must be absolute relative to where the application is running.

Ensure your files are exactly as you stated:

resources/js/
├── Pages/
│   └── Test.vue  <-- Must exist here
├── app.js        <-- Your entry point
└── ...

If the structure is correct, the issue often lies in how dynamic require handles paths that involve dots (.) versus absolute module requests.

Step 2: Refactoring the Component Resolution (The Fix)

Instead of relying on a raw require() call inside the main application entry point for dynamic page loading, it is safer and more idiomatic to use explicit dynamic imports or ensure your component registration system handles this resolution centrally.

For Inertia projects, while the provided code snippet attempts a direct file load, a more robust method involves ensuring that the components are registered in a predictable manner, often by leveraging Vite’s asset handling if you are using a modern setup recommended by Laravel ecosystem best practices.

If sticking to the require pattern for simplicity (as seen in older Inertia examples), ensure that the pathing is strictly correct relative to the entry file:

// In app.js (or wherever resolveComponent is defined)
resolveComponent: (name) => require(`./Pages/${name}`).default, 

If this still fails, it often signals an issue with your build configuration or that the module resolution environment isn't picking up the file path correctly during runtime execution.

A more reliable approach for complex applications is to use static imports where possible, or ensure your component files are named exactly as requested by the route. Since you are using Inertia, consulting the official documentation regarding asset loading and build steps can often reveal subtle configuration needs that impact these module errors. For deep dives into Laravel's ecosystem, always refer back to Laravel documentation for the most current setup guides.

Conclusion

The error Cannot find module './Test' in an Inertia/Vue context is almost always a file path or module resolution issue during the dynamic loading phase. While the provided code looks straightforward, these errors highlight the complexity of bridging server-side routing with client-side bundling. By meticulously verifying your directory structure and ensuring that your dynamic require() calls match the compiled asset paths, you can resolve this issue and continue developing robust applications on Laravel.