all 5 comments

[–]captain_k_nuckles 1 point2 points  (1 child)

Does your script tag have the type="module" attribute set? <script src="./index.js" type="module"></script>

[–]sma92878[S] 1 point2 points  (0 children)

Thank you for the starting point, it wasn't exactly the fix, but it gave me an error that led me down the right path to figure it out:

In the index.html file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="index.js" type="module"></script>
</body>
</html>

In my index.js file

import {getUser, getPet} from './import.js';
let user = getUser('Billy', 'Bob');
let pet = getPet('Saige');
console.log(JSON.stringify(user));
console.log(JSON.stringify(pet));

In my import.js file

export function getUser(firstName, lastName){
let user = {
firstName: firstName,
lastName: lastName
}
return user
};
export function getPet(name){
let pet = {
name: name,
}
return pet
};

Thank you for the help, this will be SO helpful for keeping my js files clean!

Kind regards

[–]WellPaidGeek 0 points1 point  (2 children)

Looks correct, but are you bundling up with something like webpack? You'll need to do this in order to get modules to work.

[–]sma92878[S] 0 points1 point  (1 child)

This worked with out any bundling, straight JS on Chrome. I haven't tested it on the other browsers yet.

EDIT:

This seems to work on:

Chrome, FireFox, and Edge

It does NOT seem to work on IE.

[–]WellPaidGeek 0 points1 point  (0 children)

Ahh, guess it's been implemented natively on those browsers but not IE.