TL;DR: Outside my project directory, installed with haxelib dev
, and included in Project.xml
like any other library, my library isn't seen by the Haxe compiler. Inside my project directory it works fine. Obviously other libraries don't have to be inside my project directory to avoid compiler errors, so what am I missing here?
I'm trying to release some code as a haxelib, by following this page.
I originally had my package namespace as flixel.addons
. The code sat as part of a different project, under its source/flixel/addons
subdirectory. Before I started, the project it was part of compiled fine.
I decided it would be better not to invade someone else's namespace when releasing it, so I changed the namespace to mynamespace
on the package
line of my class file. I looked at another haxelib for ideas, and saw that the library name can be different from the class path, which probably should be the same as the package namespace. So I moved the code out of my project, into a new directory elsewhere:
mylibraryname
\-Readme.md
\-haxelib.json
\-mynamespace
\-myclass.hx
Per the instructions, I ran haxelib dev
with the path to mylibraryname
.
In my project, I added <haxelib name="mylibraryname" />
to Project.xml. Where I used it, I changed the import
lines from flixel.addons.myclass
to mynamespace.myclass
.
Now, trying to compile my project (in FlashDevelop, with Haxe 3.2.1) gives the error, Type not found: mynamespace.myclass
on the import
line where it's used. The irony is that FlashDevelop added that line automatically with Ctrl+Shift+1 pressed with the cursor on myclass
where it's used. Further, I can press F4 on the red-underlined part of the import
line, and it opens myclass.hx
from its new location just fine.
That file contains:
package mynamespace;
And my project files that use it contain:
import mynamespace.myclass;
Meanwhile, the haxelib.json file has:
{
"name": "mylibraryname",
"url" : "...",
"license": "MIT",
"tags": ["haxe"],
"description": "...",
"version": "0.0.1-alpha",
"classPath": "mynamespace/",
"releasenote": "...",
"contributors": ["me"],
"dependencies": {
...
}
}
Things I tried:
Even though I believed it should be working at this point, I tried the next step of creating a zip file and using haxelib install
on it. No change.
I also happened to still have a directory mynamespace
in my project, but I didn't really need anything in it anymore, so I deleted it. No change.
Just to be sure there wasn't some typo somewhere, I plopped a copy of the mylibraryname
directory (which had installed correctly in ...\haxe\lib\mylibraryname\0.0.1-alpha
and made a .current
file with 0.0.1-alpha
in it, BTW) back into my project. It compiled fine.
Even though it's not mentioned in the docs, I saw another library include a file haxelib.xml
alongside haxelib.json
, containing this. With or without this file present, no change. (Not even to code completion, which works fine listing my class' unique and inherited variables, but generates the exact same Type not found
error in the Output pane as I get during a compile.)
haxelib selfupdate
. Was already up-to-date. No change.
Windows restart! Why not? No change.
How can I get my project to compile? Why doesn't Haxe see it when FlashDevelop and haxelib do, and when my lib's directory structure and haxelib.json
are modeled after working third-party haxelibs and the docs?
Or am I misunderstanding something, and you have to test haxelibs in the context of a project, until they're released for real? If this is the case, I'm not sure what exactly one is supposed to be doing with the haxelib dev
and haxelib install mylib.zip
steps.
The problem should be the classPath
directive in haxelib.json
.
Its value should be the relative search path for modules in the root/base package, not the path to your package.
Try changing it to ""
or omitting that directive altogether.