There are 2 files. You need to import the other into one of the files. I’m using ES6.
The extra.js file.
export function func () {
console.log ('i am func');
}
The index.js file.
import func from './extra';
func ();
Console error: “Uncaught SyntaxError: Unexpected identifier”.
Answer 1
& lt; script type = "module" src = "index.js" & gt; & lt; / script & gt;
And you also need either
export function func () {
export default function func () {
or
import func from './extra';
import {func} from './extra';