Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative path '.' is transpiled to package.json main field #415

Open
juzerzarif opened this issue Oct 26, 2020 · 3 comments
Open

Relative path '.' is transpiled to package.json main field #415

juzerzarif opened this issue Oct 26, 2020 · 3 comments

Comments

@juzerzarif
Copy link

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.

@fsmaia
Copy link

fsmaia commented Feb 18, 2021

Just found where it is coming from:

return nodePath.match(/^\.?\.\//);

The method isRelativePath isn't matching ..

@fsmaia
Copy link

fsmaia commented Feb 18, 2021

Fix suggestions:

  1. Replacing custom matcher with !path.isAbsolutePath() (reference)
  2. 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?

@fsmaia
Copy link

fsmaia commented Feb 18, 2021

Too late I guess 😆
This is a duplicate of #373, and it will be fixed on #409.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants