Installed Alpine but getting this error:-Uncaught SyntaxError: Cannot use import statement outside a module
#2020
Replies: 1 comment 2 replies
-
That is not the official way to import Alpine in a web page. If you want to get the script from remote, you should use the cdn link ( Theoretically, you can use import on a browser, but as the error says, you need to add <script type="module">
import Alpine from '/js/modules/alpine.js'
window.Alpine = Alpine
Alpine.start()
etc etc
</script> Also, you should define your data function before you start Alpine. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have installed Alpinejs using
npm install alpinejs
and then wrote this in the script tag of my index.html fileimport Alpine from 'alpinejs'; window.Alpine=Alpine; Alpine.start();
but I am getting this error:-
Uncaught SyntaxError: Cannot use import statement outside a module
How to get rid of this error?
full code of my index.html

Beta Was this translation helpful? Give feedback.
All reactions