standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Mandatory file extensions on imports #811

Closed coreyfarrell closed 5 years ago

coreyfarrell commented 5 years ago

Is it planned to impose mandatory file extensions on imports the way native node.js ESM does/will? I'm posing this question as a maintainer of nyc, so far it is not possible for nyc to support running under native ESM (lack of transpile hooks). This means ESM packages can only be tested under nyc if babel or esm is used. It would be nice if nyc -r esm npm t would throw errors if an import specifier uses extension resolution or folder to index.js resolution. Some examples that should throw:

import something from './some-file';
import something from './some-folder-containing-an-index';
import something from 'uuid/v4'; // importing non-main file of a module

I realize this would probably be a breaking change for this module and native ESM is still flagged experimental so I understand if you do not want to make this change yet.

Ref https://nodejs.org/dist/latest-v12.x/docs/api/esm.html#esm_mandatory_file_extensions

jdalton commented 5 years ago

Hi @coreyfarrell!

It's on my TODO to limit .mjs in this way. However, since esm is all about ecosystem interop by default we won't be doing this for the non-mjs case unless folks configure it.

coreyfarrell commented 5 years ago

When you say configuring it do you mean an esm module option or do you mean using package.json type="module"?

jdalton commented 5 years ago

I mean esm option. I'm still working out what type="module" means for esm configuration.