#I'm importing an array, but astro brings it in as an object

2 messages · Page 1 of 1 (latest)

verbal flickerBOT
#

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

#

Astro uses ESM (ECMAScript Modules), the same import and export syntax supported in the browser. When you import a JavaScript file, it should maintain its original data type. If you're seeing that an array is being imported as an object, it might be due to how the array is being exported from your JavaScript file.

If you're exporting an array from your JavaScript file, make sure you're using the default export like so:

// arrays.js
export default ['item1', 'item2', 'item3'];

Then, you can import it into your Astro file like this:

// your Astro file
import myArray from '../arrays.js';

If you're still having issues, it might be a good idea to check your import path and ensure that the file you're importing from actually contains the array you're trying to import. If you're still having trouble, you can create a GitHub issue (https://github.com/withastro/docs/issues/new) to alert the Astro team of the problem.

For more information on how to use import statements in Astro, you can refer to the Astro documentation (https://docs.astro.build/en/guides/imports/#import-statements).

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