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

bit import fails when one module resolution alias is a directory of another alias #2013

Closed
davidfirst opened this issue Sep 19, 2019 · 1 comment · Fixed by #2016
Closed
Assignees
Labels

Comments

@davidfirst
Copy link
Member

Describe the bug

Bit fails to import or npm install a component when is using multiple module resolution aliases where one of them is a directory of the other.

Steps to Reproduce

  1. create a component bar/foo that consists of the following three files:
    src/utils/is-type.js => ''
    src/utils/index.js => ''
    src/bar/foo => require('@/utils'); require('@utils/is-type');
  2. add the following configuration into the bit.json: resolveModules = { aliases: { '@': 'src' } };
  3. tag and export.
  4. in another workspace, import the component. You'll get the following error
unable to add the file "components/bar/foo/node_modules/@/utils/is-type", because another file "components/bar/foo/node_modules/@/utils" is going to be written.
one of them is a directory of the other one, and is not possible to have them both

Expected Behavior

The import should succeed.

Specifications

  • Bit version: 14.3.0

Additional context

Running bit cmp bar/foo@latest, shows the following:

"customResolvedPaths": [
        {
            "destinationPath": "src/utils/index.js",
            "importSource": "@/utils"
        },
        {
            "destinationPath": "src/utils/is-type.js",
            "importSource": "@/utils/is-type"
        }
    ],

Upon import, Bit generates these two link files:

@/utils
@/utils/is-type

Which is impossible because one is a directory of the other. They can't be both files.

The issue was found by a Gitter user @zeesulehria.

@davidfirst davidfirst changed the title Import is failed when one module resolution alias is a directory of another alias bit import fails when one module resolution alias is a directory of another alias Sep 20, 2019
@davidfirst davidfirst self-assigned this Sep 20, 2019
davidfirst added a commit that referenced this issue Sep 20, 2019
davidfirst added a commit that referenced this issue Sep 20, 2019
…ther alias (#2016)

* resolve #2013, fix bit import when one module resolution alias is a directory of another alias

* update bit-javascript to fix a Windows issue when Bit saves dependencies as custom-resolve when they start with "." and the config of module-resolution is set. (although the configured aliases have nothing to do with the dependency in question).
@zeesulehria
Copy link

Great work!

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

Successfully merging a pull request may close this issue.

2 participants