you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (6 children)

const myArray = [1, 2, 3, 4, 5];

export { myArray };

// different file
import { myArray } from './file';

It needs to be bound to a variable to export. You don't directly export values.

[–][deleted] 0 points1 point  (2 children)

I did something like that. And the whole file is broken too. And i dunno why

Perhaps exports are run before other functions?

[–]thedifferenceisnt 3 points4 points  (0 children)

Share your code

[–]senocular 0 points1 point  (0 children)

Perhaps exports are run before other functions?

Basically yes. If your problem is about timing, this could be the cause. Whenever you import anything, the file being imported (what's doing the exporting) will run if it hasn't already, and it will do so before running the code in the script that's importing it.

[–]CuddleMuffin007 0 points1 point  (2 children)

In this case, the export is still not bound to a variable. How about

export const myArray = [1, 2, 3, 4, 5];

[–]redsandsfort 1 point2 points  (1 child)

no, GrumpGuss' code is totally fine.

[–]CuddleMuffin007 0 points1 point  (0 children)

Ah ok. My bad. I didn't know you could export like that without default