Home javascript I get an error: “Uncaught SyntaxError: Unexpected identifier”. Tell me how to...

I get an error: “Uncaught SyntaxError: Unexpected identifier”. Tell me how to fix it? [duplicate]

Author

Date

Category

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';

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions