I have "three" files in one folder 1. index.html 2. index.js 3. helper.js
I want to export code from helper.js
and import code to index.js
(I already link up index.js
to index.html
).
I did like that index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="btn">click</button>
<script src="./index.js"></script>
</body>
</html>
index.js
import btn from './helper'
btn.addEventListener('click', function () {
window.alert('i am clicked')
})
and finally helper.js
export let btn = document.getElementById('btn')
Then I run index.html file in chrome browser.
Chrome browser showing this message in the console.
Uncaught SyntaxError: Cannot use import statement outside a module
Please tell how can I solve that problem. I search on google and youtube, I did the same thing what they showed. As a result, the browser showing that massage.