1

I'm trying to use fetch-jsonp, so I type npm i fetch-jsonp to download it and its in my package.json dependencies. Then I try to import it using:

import fetchJsonp from 'fetch-jsonp'; 

at the top of my main.js but it keep getting this error:

SyntaxError: import declarations may only appear at top level of a module

What is causing this? My file structure is:

JS -> main.js

node_modules -> fetch-jsonp

.gitignore

index.html

package.json

nameless
  • 59
  • 3
  • 9

1 Answers1

0

Type the script as a module where you reference it. Like so:

<script src="/js/main.js" type="module"></script>

See this answer for further information.

Groschenroman
  • 77
  • 1
  • 1
  • 8