rawilk / laravel-form-components

Form components built for Tailwind & Livewire.
https://randallwilk.dev/docs/laravel-form-components
MIT License
386 stars 42 forks source link

form-components/form-components.js?id= ERR_ABORTED 404 #72

Closed magarrent closed 1 year ago

magarrent commented 1 year ago

Laravel Form Components Version

^7.1

Laravel Version

9.19

Alpine Version

3.10

Bug description

In a production environment not found the form-components.js file, and nothing works:

I don't know why but it works locally. I'm using Vite. Locally works with npm run dev and build

I don't see in the Docs if I have to publish something, I use @fcStyles and @fcScripts correctly... Did I miss something? I'm the only one?

Steps to reproduce

No response

Relevant log output

GET /form-components/form-components.js?id=03553f899311a06c3381 404
players:1 Refused to execute script from '/form-components/form-components.js?id=03553f899311a06c3381' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
magarrent commented 1 year ago

Hmmm okay, after all morning trying to find out what happened...

I noticed that the 404 was an NGINX 404, not a laravel, so the request never arrived to the laravel application.

The reason: In my /etc/nginx/nginxconfig.io/general.conf I configured a cache for assets:

# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
    expires 7d;
}

The JS URL ends in .js so that's why it never ends in the laravel application and stops in the Nginx.

@rawilk I think we should think about changing the way the package loads that js, maybe include in the Vite.js and compile it? Something like this?

rawilk commented 1 year ago

The package handles this file the same way that Laravel Livewire handles its JS file that it loads. As far as I know, there shouldn't be any issues hitting the controller for that route unless your server isn't configured correctly. Personally, I haven't had any issues with it like this.

If you have issues with the external script loading, you could stop trying to load it with the @fcJavaScript directive, and instead import the source into your own js and compile it that way, but that's a measure that shouldn't ordinarily have to be taken.