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

[Severe BUG] cannot resolve symbolic directory links

Open yiakwy opened this issue 7 years ago • 5 comments
trafficstars

In my root of project "src", I created two symbolic links:

ln -s Projectxx/src/A src/A
ln -s Projectxx/src/B src/B

src/A -> Projectxx/src/A src/B -> Projectxx/src/B

For example Projectxx/src/A has file1, file2, file3, where file1 imports file2 and exports an interface to outside of the project. I used webpack in Projectxx to provide module alias:

\\ Projectxx/src/A/file1.js
import {xxx} from "A/file2"

Now in the project I am working on, I will use interfaces provided by file1

\\ src/M/endpoints/map.js
import {yyy} from "A/file1"

I have defined module aliases in .babelrc, but that doesn't work. Node throws errors because it cannot detect "A/file2"

//.babelrc
{
...
plugins: [
...
["module-resolver", {
  "root": ["./src"],
   "alias": {
     "A": "./src/A"
    }
}]
 ]
}

I think this should be a bug.

yiakwy avatar Apr 28 '18 03:04 yiakwy

same issue, anyone has solve it

aizigao avatar Feb 13 '19 06:02 aizigao

Remove the symlink and let the plugin handle the path? So the config would be to have A set to ProjectX/src/A instead.

tleunen avatar Feb 13 '19 07:02 tleunen

Solved this in react native + metro land by just aliasing to the real path of the symlink -

  plugins: [
    [
      'module-resolver',
      {
        root: './src',
        ...
        alias: {
          common: '../common/build', // common is a symlink in node_modules/common to ../common/build
        },
      },
    ],
  ],

Maushundb avatar Mar 25 '20 19:03 Maushundb

@Maushundb how is this different than the snippet of code in the original question?

asymmetric avatar Nov 23 '21 18:11 asymmetric

Rather than adding the alias to the path of the symlink, I just added the alias to the original path as a workaround

Maushundb avatar Nov 29 '21 18:11 Maushundb