How to correctly import modules in Typescript node headless environment

I am currently continuing our long-running game project and now the need for a post-processor of babylon files as part of the build pipeline is overwhelming. Loading files from the server and then changing half the stuff again on the client is just stupid. I have expressed my thoughts on this in another thread already:

So I decided to be a good sport and build a generalized and open-source solution that others can use as well. Maybe this could even become part of the babylon project itself some day (if you are interested), so I wanted to do it in Typescript (and also just to finally learn it). My approach will be to have a node app that creates a NullEngine, do all the post-processing (for example substituting materials, applying optimizations) there and export the file as babylon again.

So as a TypeScript n00b I just googled and googled until I found solutions to every issue. But this one leaves me stumped now. I get the following message:

TSError: ⨯ Unable to compile TypeScript:
src/index.ts:6:8 - error TS2307: Cannot find module '@babylonjs/core/Engines/nullEngine'.

6 } from "@babylonjs/core/Engines/nullEngine";

    [... long stacktrace]

[nodemon] app crashed - waiting for file changes before starting...

The repo is here:

And yeah, there is basically no code, just the import. The first roadblock to solve before starting to code.

On npm start you should get the same message. Is this a misconfiguration issue? Or do I need an additional npm package? The @types package for babylonjs is ancient and deprecated, so that can’t be it, and ts-loader is only for webpack right?

Thanks in advance to the TypeScript pros! Escaping JavaScripts truly weird typing rules is probably worth a little config work :wink:

BTW the reason we need this is we are modelling all of our creatures now and a lot of them have fur, which the blender exporter doesn’t/can’t support. So we’d have to check for a special material name on the client every time and apply the right fur material (possibly a ShaderMaterial, possibly a NodeMaterial, possibly a FurMaterial) for the creature after it’s already loaded. That’s just dumb. So I want to do things like that in the build phase. I imagine I am not the only one with this type of need. Or maybe I am, but anyway I’m putting it out there…

I’m by no mean expert in typescript configuration, but it seems adding "moduleResolution": "node" in the tsconfig.json file make it work.


That was it. I had tried that for another error but there was a different issue obscuring it, so removed it again. It never occurred to me that TypeScript does resolution that differently by default.


Ohhhhh yes, by default they do not look in node_modules folder: Module Resolution · TypeScript

1 Like