Referencing a typescript module within a Unity Exporter/Visual Studio Babylon project

Hi,

I have a test project I’m building using Unity Exporter/Babylon Toolkit.

Things are generally going great, however I am wanting to use a typescript library for managing events. I have installed it via npm using the command:

npm i -g strongly-typed-events

I can confirm it is installed globally:

npm install list

However, when I try to reference it, the module cannot be found

import { SignalDispatcher, SimpleEventDispatcher, EventDispatcher } from "strongly-typed-events";

I believe I’m missing something obvious.

Any ideas on what I’ve done wrong/missed?

Welcome aboard!

Have you tried to install this library locally to your project, just to see if it works that way? It could help pinpoint the problem.

Hi Evgeni,

Thanks for responding!

I have installed locally inside the project and am still getting the same error:

I will do some more digging today but I am realising that decades of using Visual Studio has protected me from a lot of this stuff.

On the plus side, the combination of Babylon and Unity is just brilliant. Having spent the last few months building AR projects in Sumerian this is a quantum leap in productivity, control and rendering quality.

Is there any way to get a more verbose output from the build process for the exporter?

Okay… I have the reference building but I don’t properly understand why (suspect it’s a path configuration issue, but would like to have a full picture).

I ran procmon to watch all file activity from node. I noticed that it was looking for a @types folder within the node_modules one. A bit of searching led to me install @types/lodash to see if that would help.

It didn’t. However, I decided to re-install strongly-typed-events locally into the project folder again to see if that helped. No dice.

Finally, I copied the folders created and populated by installing strongly-typed-events into the @types folder. This final step resolved the issue and I can now build.

Note; I am tempted to mark this as the solution, but I suspect I’ve created a configuration smell here so if someone could please explain what’s going on that would be amazing!

As an aside, some pointers to the most useful resources to learn more about npm would be greatly appreciated.

So close… but I still have issues.

Although the exporter now builds everything just fine, I now get a black scene and an error in the console (see screenshot below). This occurs only if I reference the new module in a code file. It would seem that the modules don’t get trans-piled and copied into the export folder or included into the combined js file created. Thus, when the code attempts to use it, it is not to be found.

I looked at the tsconfig.json file, I have tried specifying the extra path in there (the template version of the file - options.json). This did not resolve the issue. Is this missing functionality from the exporter or something obvious I’m missing?

The image below shows both the class that includes the reference (and builds) and the resulting console message when the page is loaded. Removing the references to the module restores the scene to full function.

Hope @MackeyK24, our Unity expert, can help us understand this error :slight_smile:

@MackeyK24 - Any pointers on this one? Assistance would be greatly appreciated :slight_smile:

I vaguely remember something about this having to do with tsc stack you are using… I think.

What version of node / npm / tsc are you using ???

Try updating them all … try node.js 12.x LTS version with latest typescript

npm install -g typescript

should just reinstall the latest.

And I dont really deal with individual modules and i dont use stuff like this:

npm i -g strongly-typed-event

and

import { SignalDispatcher, SimpleEventDispatcher, EventDispatcher } from "strongly-typed-events";

If that dont work… package up your Unity project and send to me (private message if you need)… and i will take a look at in new GLTF 2.0 version with a slightly different build stack… although i still dont do

npm i -g strongly-typed-event
1 Like

Thanks for the response!

npm -v returns 6.14.7
tsc -v returns 3.9.7
node -v return 14.7.0 (which is slightly outdated)

I’m happy to zip up the Unity project as well. A quick question however; when you say you don’t deal with individual modules do you mean that you don’t use them in your own projects, or that that isn’t recommended or that they’re not supported by the exporter?