Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brian_corecommerce's avatar

Asset URL's in Laravel Vapor

We are using Vapor with AWS Lambdas, and I cannot seem to get the asset helper working in javascript, at least locally it doesn't work. I following the documentation installing the necessary library with

npm install --save-dev laravel-vapor

then adding this to app.js

window.Vapor = require('laravel-vapor');

This just gives the error that require isn't a valid command, so somehow the code isn't being built correctly on my local machine. NOTE: we are using Inertia with Vue 3 and Vite, so I'm sure this is part of the issue. Any help is appreciated, is there a specific process to run a Vapor app locally, we are using Sail to run the app locally.

0 likes
6 replies
thinkverse's avatar

Vite uses ESM imports, require isn't available, it's only available when Node uses CommonJS. Switch to using import and from instead.

import Vapor from 'laravel-vapor'

You can read more in the PR that added Vite support.

azbx's avatar

Update Vapor npm install laravel-vapor then try Vapors ESM

import Vapor from 'laravel-vapor'

or try this

import Vapor from '@laravel/laravel-vapor'

thinkverse's avatar

@[aeo] Vue has scoped packages, which it uses internally and for types.

Why should OP install the package again? OP has already installed it? The issue is require isn't available when using ESM.

1 like

Please or to participate in this conversation.