I’ve been trying to develop a dev environment that lets me use TypeScript + ExpressJS rather than Webpack + Webpack server. I can build the server-side fine compiling to es6, but am stumped how to compile the browser code so that imports pull in the babylon libraries with correct typing.
- If you use something like:
import { Scene } from ‘@babylonjs/core/scene’;
It works fine for the typescript compile, but the resulting JS can’t load the libraries in the browser. I
In all cases, the result is:
Uncaught TypeError: Failed to resolve module specifier “@babylonjs/core/”. Relative references must start with either “/”, “./”, or “…/”.
I’ve tried adjusting vales in tsconfig.json in several ways, here is one example:
tsconfig.json
…
“target”: “es2017”,
“module”: “esnext”,
“moduleResolution”: “node”,
…
But it doesn’t work.
And, in TypeScript, you can’t specify an import using the .js,
import { Scene } from ‘@babylonjs/core/scene/index.js’;
You could use pure JS like:
BABYLON = require("./vendor/babylon.min.js")
…but then you lose the TypeScript typing, which is the whole point of TypeScript. You can write
let s = new BABYLON.Scene()
but TypeScript won’t know what type ‘Scene’ is, because it was dynamically loaded. You lose the ability to declare
…
private _scene:Scene;
in your classes.
Does anyone have a (non-Webpack) strategy for getting JS using node_module imports to work in the browser? Some funky tsconfig.json values? Thanks!