1

I've scoured SO and the Web for answers, but have found nothing so far that has helped. When navigating to my test site (see below), I'm getting this error: Importing binding name 'Person' is not found.

From index.html:

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

From script.js:

import {Person} from '/js/person.js';

From person.js:

export class Person {
  constructor(
    firstName, lastName, email
  ){
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
  }

  setFirstName(firstName){
    this.firstName = firstName;
  }

  setLastName(lastName){
    this.lastName = lastName;
  }

  setEmail(email){
    this.email = email;
  }

}

All the documentation I've found appears to indicate that I'm doing this correctly, and yet I get the error. Any ideas, anyone?

UPDATE Everything works fine under Windows, but not using MacOS 12 in Safari, Firefox, or Chrome. Why?

6
  • from '/js/person.js'; -> from 'js/person.js'; probably. You're importing from different paths. And I don't think you need to add person.js on the page itself, script.js referencing it should be enough. Commented Feb 19, 2022 at 8:19
  • @VLAZ that doesn't work-- it generates this error: TypeError: Module specifier, 'js/person.js' does not start with "/", "./", or "../". Commented Feb 19, 2022 at 8:22
  • Oh, right - they'd be in the same folder. Then from './person.js' Commented Feb 19, 2022 at 8:22
  • @VLAZ-- tried that as well, got the same SyntaxError: Importing binding name 'Person' is not found. error. Commented Feb 19, 2022 at 8:24
  • Weird - where are your files located in relation to each other? Commented Feb 19, 2022 at 8:25

2 Answers 2

1

Issue resolved; I was using the 'Live Server' plugin in VS Code on MacOS to serve the site which apparently caused the problem (although under Windows, it works just fine). When serving it with Apache on MacOS, it works.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for coming back and updating your question.
1

A cause of this error message (though not in OP's case) is, when importing from a module with a default export, using

import {defaultName, otherName} from ...

instead of

import defaultName, {otherName} form ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.