#Difference in Build and Dev

3 messages · Page 1 of 1 (latest)

half cape
#

When i do dynamic imports to use <Image/>, i do this:

imageComponents = (await import(imagePath)).default;

This works perfectly when running npm run dev. However, when doing npm run build - import cant find the same file since it is in the folder "dist/chunks". If i try to break out by prefixing ../../ to the imagePath, dynamic imports no longer accepts / understands image-files.

The same as above goes for Astro.glob - I can do it in dev - but whenever build is being run, it doesn't work anymore.

sand roverBOT
#

Hi @half cape. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems like you're encountering issues with dynamic imports and Astro.glob() during the build process.

For dynamic imports, Astro supports both static and dynamic ESM imports. However, it's important to note that any asset inside of src/ that is imported using an ESM import will have its filename hashed automatically during the build process. This could be the reason why your dynamic imports can't find the same file in the dist/chunks folder during the build process. You might want to check the hashed filename and adjust your import path accordingly. source (https://docs.astro.build/en/guides/upgrade-to/v1)

As for Astro.glob(), it's a way to import many files at once and it only takes one parameter: a relative glob pattern matching the local files you'd like to import. However, Astro.glob() does not support dynamic variables and string interpolation. This is due to a limitation of Vite’s import.meta.glob() function which only supports static string literals. A common workaround is to import a larger set of files that includes all the files you need using Astro.glob(), then filter them. source (https://docs.astro.build/en/guides/troubleshooting)

If you're still encountering issues, it might be helpful to refer to the Astro documentation (https://docs.astro.build) or the Astro GitHub issues (https://github.com/withastro/astro/issues) for further troubleshooting.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: