# How to import fields from a module automatically?

**URL:** https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705
**Category:** Haxe
**Created:** [November 11, 2025, 10:19pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705 "2025-11-11T22:19:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Davvex87](https://community.haxe.org/user_avatar/community.haxe.org/davvex87/32/2399_2.png) [@Davvex87](https://community.haxe.org/u/Davvex87)
#### Post date: [November 11, 2025, 10:19pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/1 "2025-11-11T22:19:01Z")

</div>

For my [roblox-hx](https://github.com/Davvex87/roblox-hx) project I need to automatically add some extern fields as global variables to be used by any haxe script at any time without having to manually import the module containing these extern fields. The project is for compiling haxe into roblox luau, but luau scripts in roblox have some context information data which auto adds a few global environment variables to the luau vm like the “Script” variable which references the current Script Instance in the engines explorer hierarchy, but i can’t really find a reliable way to bridge the gap for this problem.

---

<div class="post-metadata">

### Author: ![PaperPrototype](https://community.haxe.org/user_avatar/community.haxe.org/paperprototype/32/2524_2.png) [@PaperPrototype](https://community.haxe.org/u/PaperPrototype)
#### Post date: [November 11, 2025, 10:49pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/2 "2025-11-11T22:49:02Z")

</div>

What options have you tried so far?

---

<div class="post-metadata">

### Author: ![Davvex87](https://community.haxe.org/user_avatar/community.haxe.org/davvex87/32/2399_2.png) [@Davvex87](https://community.haxe.org/u/Davvex87)
#### Post date: [November 11, 2025, 11:04pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/3 "2025-11-11T23:04:47Z")

</div>

using autoBuild macros which just adds an extern field to the current class but that brings some issues with completion (sometimes the lsp just gives up even if the field exists) and duplicate fields. I saw that the StdTypes.hx file in the haxe std library contains abstracts automatically imported into all scripts, but those are types, not variables/fields…

---

<div class="post-metadata">

### Author: ![Davvex87](https://community.haxe.org/user_avatar/community.haxe.org/davvex87/32/2399_2.png) [@Davvex87](https://community.haxe.org/u/Davvex87)
#### Post date: [November 12, 2025, 2:49pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/4 "2025-11-12T14:49:11Z")

</div>

Just remembered that the `trace` function is also auto imported from `haxe.Log`. Does anybody know how that works?

---

<div class="post-metadata">

### Author: ![player\_03](https://community.haxe.org/user_avatar/community.haxe.org/player_03/32/821_2.png) [@player\_03](https://community.haxe.org/u/player_03)
#### Post date: [November 14, 2025, 10:26pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/5 "2025-11-14T22:26:03Z")

</div>

Have you tried making a top-level [_import.hx_ file](https://haxe.org/manual/type-system-import-defaults.html)?

---

<div class="post-metadata">

### Author: ![Davvex87](https://community.haxe.org/user_avatar/community.haxe.org/davvex87/32/2399_2.png) [@Davvex87](https://community.haxe.org/u/Davvex87)
#### Post date: [November 14, 2025, 11:46pm UTC](https://community.haxe.org/t/how-to-import-fields-from-a-module-automatically/4705/6 "2025-11-14T23:46:15Z")

</div>

I have and that’s the approach that I’m using right now but I’d like to not have an import.hx in every class path on every project made with this lib. Unless there’s some other way to include an import.hx file inside the extraParams.hxml file of my lib which auto adds the given imports to all modules I haven’t discovered.
