-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Production build fails on static deployments when using path aliases #11090
Comments
Update, I found a solution to the issue: Due to astro using To fix this, you'll need to extend your astro configuration like so: import { path } from 'path'
export default defineConfig({
vite: {
resolve: {
alias: {
// your aliases should mirror the ones defined in your tsconfig.json
// i'll re-use the ones in the official docs:
"@components": path.resolve(path.dirname(''), './src/components'),
"@assets": path.resolve(path.dirname(''), './src/assets')
}
}
}
}) Ideally this should be done by codemod when installing the astro deployment integration, but for now I've atleast submitted a PR which updates the docs. |
Even if you are not able to run it in Stackblitz, it's still helpful to have a reproduction. Just tell us that it needs to be pulled down locally in order to see the bug. |
Hello @samuelhulla. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Many people uses aliases configured like the docs says through tsconfig just fine in production, I'm not too sure what your issue is. |
Hmm strange. I found it bit odd that more people didn't run into it (couldn't find any similar issues) but I just chucked it off to people not using aliases with static deployment. I'm only on phone since I'm away for the weekend, so sadly can't create a minimal code repo, either way, here's how to reproduce the issue:
"paths": {
"@/*": ["./src/*"]
}
If this for whatever reason does not work -- I've got a public repository where this happens:
|
The baseUrl in your example repo is wrong, it should be |
Hi, this is my first post ever to try help, sorry if that's not how I should do it. Currently working on an astro project, I used aliases following the doc, and it works on my side when deploying the Github page, as Princesseuh said you did not set the baseUrl properly @samuelhulla
Hope this helps |
@Princesseuh Yeah that's embarassing, I have no clue how that path got there instead of the Can confirm it works when you fix the Sorry for the confusion, a silly oversight 😆 ps: @Tiffany-Dby dw, the more people try to help the merrier. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
There seems to be an issue with path resolution in production deployments of static
astro
.Initially I thought this issue is in vercel itself, which I was deploying to, but I tried also other supported deployments to double-check and indeed - I got the same error.
In specific
Running
bun run build
locally, does workI also tried using the
@astrojs/vercel
integrtio, but it does not helpWhat's the expected result?
Assumption: Under inspecting the logs further, this is due to the fact, that astro uses
vite
, which acts differently in production environment compared to local.I would expect either
vite
to work with path aliases.Creating
vite.config.ts
and specifying path aliases resolvers does not workLink to Minimal Reproducible Example
unlinkable to astro.new, stackblitz sadly breaks when you use a import path alias
Participation
The text was updated successfully, but these errors were encountered: