Relative path '.' is transpiled to package.json main field
I have a directory structure as follows:
src/some/directory
├── SomeModule.js
└── index.js
And I have a main field specified in my package.json: "main": "src/main.js". If I have a relative import of index.js in SomeModule.js, it gets transpiled to the main field from the package.json.
import utils from '.'; // gets transpiled to '../../main'
import utils from './'; // works
Will try to look into where the resolution is coming from a bit more after work today.
Just found where it is coming from: https://github.com/tleunen/babel-plugin-module-resolver/blob/f533cc2b43f867c213d4f7c87bf437a2e2280a4b/src/utils.js#L13
The method isRelativePath isn't matching ..
Fix suggestions:
- Replacing custom matcher with
!path.isAbsolutePath()(reference) - Refining the regex to make slash optional
This leads me to a question: is there a reason to have a custom matcher? Is there any use case where resolving . to the current package.json main entry is the desired behavior?
Too late I guess :laughing: This is a duplicate of #373, and it will be fixed on #409.