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 paths are broken on Windows #956
Comments
Hi @scott-cornwell! There are already a lot of issues about aliases (eg. #811, #658, #652, etc.). The only working solution right now is using |
I tried that but it's not working for me. It seems like somewhere along the line it's just not using the Also I did see those other issues, but they are different. This is dealing specifically with Windows paths, which babel-plugin-module-resolver does not seem to fix. |
I think I found where it happens, but it's in enhanced-resolve itself that is the problem. I have raised an issue there, I believe the problem is this line https://github.com/webpack/enhanced-resolve/blob/main/lib/AliasPlugin.js#L70 I'm trying to make my own modified AliasPlugin that is fixed but the plugin does not seem to get run. Hopefully they can fix it. |
@Anber Ok I figured it out, actually it works it's just very confusing to set up. I had to define my aliases twice, once for webpack resolve with absolute paths, and once for babel-plugin-module-resolver for linaria with relative paths. Would be good to document how to actually use this with linaria! In webpack resolve: resolve {
extensions: [".js", ".jsx"],
alias: {
_utils: path.resolve(__dirname, "src/utils/"),
_components: path.resolve(__dirname, "src/pages/"),
}
} In linaria loader: { loader: '@linaria/webpack-loader',
options: {
sourceMap: true,
displayName: true,
babelOptions: {
plugins: [
['babel-plugin-module-resolver', {
extensions: ["*.js", "*.jsx"],
root: "./src",
alias: {
"_utils": "./src/utils/",
"_components": "./src/components/",
}
}],
]
}
}
} This allows me to have fully working aliases on Windows with Linaria! |
"webpack": "^4.44.2",
"@linaria/babel-preset": "3.0.0-beta.2",
"@linaria/core": "3.0.0-beta.2",
"@linaria/react": "3.0.0-beta.2",
"@linaria/shaker": "3.0.0-beta.2",
"@linaria/webpack-loader": "3.0.0-beta.1",
node 14.15.5
Windows 10
Description
I'm defining webpack aliases like this:
The files that go through linaria loader don't handle paths right for Windows. The path to resolve to for the alias turns into a Windows path, but the part from the actual import, something like this:
just gets concatenated with the alias path to something like this:
My\Windows\Path\utils/responsive
I tried a lot of different versions of linaria packages and some other ways to try and rewrite these paths but nothing has worked.
The text was updated successfully, but these errors were encountered: