P
P
Pavel Sachenko2020-05-01 12:48:52
JavaScript
Pavel Sachenko, 2020-05-01 12:48:52

How to do import/export in js?

The essence of the error is that when I specify the type of the javascript file as modular, the functions stop working. Writes what

function is not defined
If you specify the type to text/javascript - the functions work, but the connection of modules stops working.
I include the file in head
<script src="public/src/script.js" type="module"></script>

in body for test button:
<button onclick="f()">
        TEST
    </button>

script.js file
import {arr} from "./windows/Popup.js";

export function f() {
    console.log(arr);
}

Popup.js file:
export let arr = 3.354;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Sachenko, 2020-05-01
@PavelSachenko

If you change the code a bit to:

<button  id="identify">
        TEST
    </button>

import {arr} from "./windows/Popup.js";

document.querySelector("#identify").addEventListener('click', () => {
    console.log(arr);
})

Then everything will work, but I need it to be without an identifier, so that I can call f-u from the html file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question