Multiple Alpinejs file causes error #2894
Replies: 2 comments 2 replies
-
Third parties shouldn't inject the CDN script, it's poor coding at their end. They should either ask users to include the cdn script or bundle the npm version in a separate namespace and use a custom prefix for directives to avoid clashes. I don't think there's anything you can do, either find different libraries or try to reach out to those vendors. |
Beta Was this translation helpful? Give feedback.
-
The cdn was just an example. Even with the npm bundle, two alpine files load. How do you namespace your alpine initializer? Let's say both vendors have this codes. Vendor A:
Vendor B:
Vendor A bundle file will through an error for the undefined Vendor B is my code and How do I namespace it? Thanks |
Beta Was this translation helpful? Give feedback.
-
Hello!
I found an interesting issue with multiple alpinejs files on one page.
To explain it simply, having two alpine file through errors.
<script src="//unpkg.com/alpinejs" defer></script>
<script src="//unpkg.com/alpinejs" defer></script>
The first alpine initializer through errors because it can't find components of the second alpine file.
You might ask, remove one of them, that fixes the issue but I don't have control over this.
Let's say 2 third-party apps inject codes and both use Alpine. That's causing errors in the console and some components stop working.
Does anyone have any workaround for this?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions