Skip to main content
added 1 character in body
Source Link
paul23
  • 9.6k
  • 17
  • 80
  • 171

While trying to troubleshoot why systemjs didn't find a custom library I installed (could be a follow up question) I was stuck when trying to do things "manually".

So I have a simple system that consists of 3 files:

  • index.html
  • hi.js
  • hi2.js

the index is just:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <script src="hi.js"></script> </body> </html> 

hi.js:

import * as hi from "hi2.js"; hi.myFunction(); 

hi2.js:

function myFunction() { alert('hi') } export { myFunction }; 

Now when I run (using webstorm and chrome 262) above code, I get the following error, reported by the (chrome) debugger: "Uncaught SyntaxError: Unexpected token import"

What's happening here? I checked for javascript compliance on mdn and it tells me import is supported by chrome 61 and newer. - I use chrome 62 for testing this.

So what's going on, and how to make it work?

Per recomendation I also changed the html line to <script type="module" src="hi.js"></script>. That didn't help at all, same error.

While trying to troubleshoot why systemjs didn't find a custom library I installed (could be a follow up question) I was stuck when trying to do things "manually".

So I have a simple system that consists of 3 files:

  • index.html
  • hi.js
  • hi2.js

the index is just:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <script src="hi.js"></script> </body> </html> 

hi.js:

import * as hi from "hi2.js"; hi.myFunction(); 

hi2.js:

function myFunction() { alert('hi') } export { myFunction }; 

Now when I run (using webstorm and chrome 2) above code, I get the following error, reported by the (chrome) debugger: "Uncaught SyntaxError: Unexpected token import"

What's happening here? I checked for javascript compliance on mdn and it tells me import is supported by chrome 61 and newer. - I use chrome 62 for testing this.

So what's going on, and how to make it work?

Per recomendation I also changed the html line to <script type="module" src="hi.js"></script>. That didn't help at all, same error.

While trying to troubleshoot why systemjs didn't find a custom library I installed (could be a follow up question) I was stuck when trying to do things "manually".

So I have a simple system that consists of 3 files:

  • index.html
  • hi.js
  • hi2.js

the index is just:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <script src="hi.js"></script> </body> </html> 

hi.js:

import * as hi from "hi2.js"; hi.myFunction(); 

hi2.js:

function myFunction() { alert('hi') } export { myFunction }; 

Now when I run (using webstorm and chrome 62) above code, I get the following error, reported by the (chrome) debugger: "Uncaught SyntaxError: Unexpected token import"

What's happening here? I checked for javascript compliance on mdn and it tells me import is supported by chrome 61 and newer. - I use chrome 62 for testing this.

So what's going on, and how to make it work?

Per recomendation I also changed the html line to <script type="module" src="hi.js"></script>. That didn't help at all, same error.

Source Link
paul23
  • 9.6k
  • 17
  • 80
  • 171

"import" unexpected token? (chrome 62)

While trying to troubleshoot why systemjs didn't find a custom library I installed (could be a follow up question) I was stuck when trying to do things "manually".

So I have a simple system that consists of 3 files:

  • index.html
  • hi.js
  • hi2.js

the index is just:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <script src="hi.js"></script> </body> </html> 

hi.js:

import * as hi from "hi2.js"; hi.myFunction(); 

hi2.js:

function myFunction() { alert('hi') } export { myFunction }; 

Now when I run (using webstorm and chrome 2) above code, I get the following error, reported by the (chrome) debugger: "Uncaught SyntaxError: Unexpected token import"

What's happening here? I checked for javascript compliance on mdn and it tells me import is supported by chrome 61 and newer. - I use chrome 62 for testing this.

So what's going on, and how to make it work?

Per recomendation I also changed the html line to <script type="module" src="hi.js"></script>. That didn't help at all, same error.