1

When importing ES6 modules on my Windows pc I'm able to easily use:

import {Person} from '/person';

However when I switch over to my Mac I'd have to use:

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

Is there a way to disable the use of the .js extension? I'm using MAMP.

Thank you.

Danny
  • 65
  • 5
  • Yes I am. I also mentioned MAMP as it's the only notable difference between the two systems (apart from the obvious OS), so I thought it would be worth mentioning. – Danny Mar 03 '19 at 18:04
  • I don't know if it is a suitable solution, but you could easily check the operating system with the ternary operator: `import {Person} from navigator.platform.indexOf("Win") == -1 ? './person.js' : '/person';` – Habebit Mar 03 '19 at 18:27
  • 1
    Tabman, that won't work, you cannot construct import statements with dynamic expressions like that – Patrick Hund Mar 03 '19 at 18:34
  • 1
    Danny, are you talking about using these import statements in the browser, or with node.js? I don't think the operation system is the issue, but rather which browser with which version, or, if using node.js, which version of that – Patrick Hund Mar 03 '19 at 18:37
  • @PatrickHund If he's talking about modules in the browser, the server (and by extension the OS that the server is running on) might very well be the issue if it doesn't serve a file on the `/person` URL but only on `/person.js`. – Bergi Mar 03 '19 at 18:50
  • @PatrickHund I am talking about using these imports on the browser. I can confirm the browser version on both my Mac and Windows pc are the same. The /person url does not serve a file, but /person.js does. – Danny Mar 03 '19 at 19:19

0 Answers0