Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

`import` and `export`

So I have 2 js files set up like this:

// module.js
export {CONST1, CONST2};

// constant declarations for`CONST1` and CONST2 `.
// main.js
import { CONST1, CONST2 } from "/scripts/module.js";

// functions and other things involving `CONST1` and `CONST2`.

Both files are under "/scripts/". And main.js is referenced in index.html:

...
<script src="scripts/main.js"></script>
...

When I run this on my local server, I got an error message on my console:

SyntaxError: Unexpected token '{'. import call expects exactly one argument.

I've read the official documentation on imports and also looked up on MDN import and export, and still don't get why there is a SyntaxError (unless Safari does not support ES6?).

Or is there a more standard way to use functions and variables from another file?

Which version of Safari are you using? you can use it from version Safari 10.1. https://jakearchibald.com/2017/es-modules-in-browsers/

The link is very helpful. I missed type="module" in my script tag.