Error: "Uncaught Syntaxerror: Unexpected token import" in javascript

Asked

Viewed 1,519 times

0

good afternoon, I have the following program:

testing.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title> Testando </title>
  </head>
  <body> 

    <p> oi </p>

    <script language="JavaScript" src="arquivo.js"></script>


  </body>
</html>

and the file.js:

  import { createStore } from 'redux';

  function oi(a)
  {
    console.log(a)
  }

  console.log("oi")
  let a=4
  oi(a)

I’m trying to learn how to use Redux, but when using import, the browser gives me the error : Uncaught Syntaxerror: Unexpected token import. I’d like to know why you made a mistake

  • Which browser you are using?

  • Are you using webpack ? or Babel ? How are you compiling/running the code ?

  • Managed to solve?

  • got yes, I imported the Redux in a script before calling the.js file, so it worked cool, thanks for all help :3

1 answer

0

You are using Javascript modules. You must enter the attribute type="module" on the tag <script>:

<script type="module" language="JavaScript" src="arquivo.js"></script>

There is a question that deals with the subject at this link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.