Code Monkey home page Code Monkey logo

Comments (8)

samuelhulla avatar samuelhulla commented on June 2, 2024

Update, I found a solution to the issue:

Due to astro using vite which uses esbuild / rollup differing on local and production environments, this led to this diversion in build statuses.

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.

withastro/docs#8323

from astro.

matthewp avatar matthewp commented on June 2, 2024

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.

from astro.

github-actions avatar github-actions commented on June 2, 2024

Hello @samuelhulla. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

from astro.

Princesseuh avatar Princesseuh commented on June 2, 2024

Many people uses aliases configured like the docs says through tsconfig just fine in production, I'm not too sure what your issue is.

from astro.

samuelhulla avatar samuelhulla commented on June 2, 2024

@matthewp @Princesseuh

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:

  1. Create new astro app
  2. Add a path alias to tsconfig.json i.e.
"paths": {
  "@/*": ["./src/*"]
}
  1. In a page (index.astro) change a component import from ../ to @/

  2. Trying deploying (I tried vercel and render and got the same error on both)

If this for whatever reason does not work -- I've got a public repository where this happens:

  1. Clone https://github.com/samuelhulla/hulla.dev
  2. Edit index.astro to a path alias import @/
  3. Try deploying

from astro.

Princesseuh avatar Princesseuh commented on June 2, 2024

The baseUrl in your example repo is wrong, it should be .

from astro.

Tiffany-Dby avatar Tiffany-Dby commented on June 2, 2024

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

// tsconfig.json
{
   // .. rest
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": [
        "src/components/*"
      ],
      "@assets/*": [
        "src/assets/*"
      ],
      "@layouts/*": [
        "src/layouts/*"
      ],
      "@scripts/*": [
        "src/scripts/*"
      ]
    }
  }
}

Hope this helps

from astro.

samuelhulla avatar samuelhulla commented on June 2, 2024

@Princesseuh Yeah that's embarassing, I have no clue how that path got there instead of the . (i guess i just tabbed away and copilot halucinated something) and it didn't even occur to me to check it, since I pretty much always use . in all of my projects.

Can confirm it works when you fix the baseUrl to ..

Sorry for the confusion, a silly oversight 😆


ps: @Tiffany-Dby dw, the more people try to help the merrier.

from astro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.