-
Notifications
You must be signed in to change notification settings - Fork 205
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
Alias resolves to wrong alias when used inside aliased code #96
Comments
Hi @Mythli, thank you for the great description. Is your issue when building Do you think it would be possible to setup a very small project reproducing the issue? It would help to find the root cause by reproducing it. |
Hi, I will provide a testcase to resolve the issue. |
Hi, I’ll add my contribution to this issue as I think it’s related to mine 😄 I’m working on a project which is kind of a starter-kit for all our future apps, so we splitted our original app in multiple modules, like this:
We do not want to make distributables for our modules, so we keep the code as is and rely on the We just switched to We have our
So we have a redundant dependency, which is handled by npm like a charm, but not by In fact, when we launch the tests from Here is the directory tree of utils (simplified):
As you can see, If you have any question regarding my overcomplicated explanation, just ask 😄 EDIT: I forgot to add the {
"ignore": "node_modules(?!\/aw-.+)",
"plugins": [
"transform-es2015-modules-commonjs",
"transform-async-to-generator",
"transform-class-properties",
"transform-decorators-legacy",
"transform-object-rest-spread",
["module-resolver", {
"cwd": "babelrc",
"root": ["./"],
"alias": {
"aw-utils": "./"
}
}]
]
}
{
"ignore": "node_modules/(?!aw-.+)",
"plugins": [
"transform-es2015-modules-commonjs",
"transform-class-properties",
["module-resolver", {
"cwd": "babelrc",
"root": ["./"],
"alias": {
"aw-scripts": "./"
}
}]
]
} |
Thank you @nicolas-goudry for the explanation, but it's really hard for me to understand what's going on with the plugin in this specific case without having any working example. Would you be able to setup a small project to reproduce the issue? When you say you're running the tests from
|
@nicolas-goudry If you remove the custom |
In my code I use something like:
However the transpiled path is: |
Interesting... I'll try to reproduce this particular issue |
@tleunen Sorry to reply so late!
I don’t have access to the source code anymore because I left the company behind this project… So it would be hard to reproduce it for me.
No, we were running tests with mocha only on
I can’t tell you what would happen neither… Sorry 😕 |
@Mythli - Do you still have the issue? Were you able to reproduce it outside of your repo? Running this test works fine... describe('#96', () => {
const rootTransformerOpts = {
babelrc: false,
plugins: [
[plugin, {
alias: {
mythil: './build/lib/mythil.js/src',
},
}],
],
};
testRequireImport(
'mythil/time',
'./build/lib/mythil.js/src/time',
rootTransformerOpts,
);
}); |
They test the behavior described in: tleunen#96 (comment)
The behavior I have observed is that when I use an alias inside of another alias one path backward is somehow skimmed in my folder structure.
The same works with webpack which I use on the client side.
Babelrc:
Folder structure:
Files are compiled into the build directory using this command:
./node_modules/.bin/babel src -d build && ./node_modules/.bin/babel lib -d build/lib && node build/index.js
The build dir then looks like this:
When running the command compiling with babel works fine. However running the code encounters a module resolve error:
In constants.js which is accessed through the alias libbehoerdenglueck the following line fails:
import { mToMs, sToMs, dToMs, hToMs } from 'mythil/time';
babel-plugin-module-resolver translates the alias mythil/time to
../../../build/lib/mythil.js/src/time
instead of the correct../../../../build/lib/mythil.js/src/time
(one path backward is missing).All that is pretty sad :(
Would love to see replications of the issue and possible workarounds.
Workaround:
find ./build -type f -name '*.js' -exec sed -i '' s@../../../build@../../../../build@ {} +
Best regards
Mythli
The text was updated successfully, but these errors were encountered: