babel-plugin-module-resolver
babel-plugin-module-resolver copied to clipboard
How to alias a path to another project?
Hi,
For Project_B, I need to use some components from Project_A
Project_B's .babelrc is in the root of it's directory, and I need to specify a path above it so I can access Project_B.
I've tried several things using cwd and root, but no luck.
Please help. Thanks!
root --Project_A ----src ------components --Project B ----src
Hi !
I am having the same issue here. I assumed option "cwd" was supposed to resolve this, but either it doesn't work, or I am doing something wrong.
I have a project "A", in which I have aliases.
// .babelrc in project A
{
"plugins": [
"transform-es2015-modules-commonjs",
"transform-class-properties",
["transform-object-rest-spread", { "useBuiltIns": true }],
["module-resolver", {
"cwd": "babelrc",
"root": ["./"],
"alias": {
"@project-a-alias": "./a-directory-from-project-a",
}
}]
]
}
Now it works fine in project A. But I have a project B, which uses project A as a dependance.
// .babelrc in project B
// the ignore allows me to use babel on project A since it's in ./node_modules/project-a
{
"ignore": "node_modules(?!\/project-a)",
"plugins": [
"transform-es2015-modules-commonjs",
"transform-class-properties",
["transform-object-rest-spread", { "useBuiltIns": true }],
["module-resolver", {
"cwd": "babelrc",
"root": ["./"],
"alias": {
"@project-b-alias": "./a-directory-from-project-b",
}
}]
]
}
When I import a file from project A in project B, the aliases from project A are not working.
The error i'm receiving :
ERROR in ./node_modules/project-a/path/to/some/file.js
Module not found: Error: Can't resolve '@project-a-alias/path/to/other/file' in 'D:\project-b\node_modules\project-a\path\to\some\file'
Is this a bug, or am i doing something wrong ?
In general it seems like Babel can't apply the transform properly - probably the other config is not taken into consideration at all. I'd recommend putting everything into one .babelrc file, otherwise I'm not sure what the behavior will be. It's more about babel than about the plugin itself.
Do you have a babelrc file in ./node_modules/project-a?