Jesus Michel
Jesus Michel

Reputation: 31

Javascript export/import doesn't work

I just want to import a custom js module on another js file.

on html head:

<script  src="Dictionary.js" type="module"></script>
<script type="text/javascript" src="Templates.js" ></script>

On Module:

 var Dictionary=function() {...}
 export {Dictionary};

On js File:

import {Dictionary} from './Dictionary';

I get these errors

On Chrome:

Uncaught SyntaxError: Unexpected token {

On Firefox

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

The two files are in the same folder.

Upvotes: 1

Views: 1728

Answers (1)

Sid Ali
Sid Ali

Reputation: 1867

When importing don't add the ".js"

import {Dictionary} from 'Dictionary';

See the doc here

Upvotes: 1

Related Questions