Skip to content

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

Open

Description

@juzerzarif

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.

Activity

  1. fsmaia commented on Feb 18, 2021

    @fsmaia

    Just found where it is coming from:

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

    The method isRelativePath isn't matching ..

  2. fsmaia commented on Feb 18, 2021

    @fsmaia

    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?

  3. fsmaia commented on Feb 18, 2021

    @fsmaia

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions