babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

How to not remove trailing '/index' ?

Open ExcitedSpider opened this issue 4 years ago • 3 comments

Is there any options that can control whether to remove trailing '/index' in path ?

import a from 'packages/a/index'

ExcitedSpider avatar Oct 12 '20 07:10 ExcitedSpider

I believe we do remove index? Because it's the default behavior.

What situation makes you willing to have an option to decide this?

tleunen avatar Oct 19 '20 14:10 tleunen

I found this feature when run code in node environment using node esm.

I believe that node doesn't take this as a default behavior. In the API document (#esm_differences_between_es_modules_and_commonjs):

A file extension must be provided when using the import keyword. Directory indexes (e.g. './startup/index.js') must also be fully specified.

This behavior matches how import behaves in browser environments, assuming a typically configured server.

ExcitedSpider avatar Oct 21 '20 06:10 ExcitedSpider

Interesting, so it's a bit specific to esm I believe. Wonder if we could revert our decision to strip the extension and index name. @fatfisz what do you think?

tleunen avatar Oct 21 '20 13:10 tleunen