2

I am following a guide to setup a simple BabylonJs example with npm, webpack, typescript and ES6 (https://doc.babylonjs.com/divingDeeper/developWithBjs/npmSupport) and get the following error when running npm run build:

ERROR in ./index.ts 3:17-58
Module not found: Error: Can't resolve '@babylonjs/core/Engines/engine' in 'C:\...\BabylonJSPlayground\HelloWorld'

... same error for other modules in @babylonjs/core

My npm installations:

npm init
npm install --save-dev webpack webpack-cli typescript ts-loader
npm install --save @babylonjs/core @babylonjs/materials @babylonjs/loaders @babylonjs/post-processes @babylonjs/procedural-textures @babylonjs/serializers @babylonjs/gui @babylonjs/inspector

webpack.config.js:

const path = require("path");

module.exports = {
    entry: './index.ts',
    output: {
        filename: 'index.js',
        path: path.resolve(__dirname, 'dist')
    },
    resolve: {
        extensions: [".ts"]
    },
    module: {
        rules: [
            { test: /\.tsx?$/, loader: "ts-loader" }
        ]
    },
    mode: "development",
    externals: {
        "oimo": true,
        "cannon": true,
        "earcut": true
    },
};

tsconfig.json:

{
    "compilerOptions": {
        "module": "CommonJS",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "moduleResolution": "Node",
        "lib": ["ES6","DOM"],
        "target": "ES6",
        "types": [
            "@babylonjs/core",
            "@babylonjs/gui",
            "@babylonjs/inspector",
            "@babylonjs/loaders",
            "@babylonjs/materials",
            "@babylonjs/post-processes",
            "@babylonjs/procedural-textures",
            "@babylonjs/serializers"
        ],

    },
    "files": [
        "./index.ts"
    ]
}

The imports in my index.ts (vscode shows now errors of missing modules):

import { Engine } from "@babylonjs/core/Engines/engine";
import { Scene } from "@babylonjs/core/scene";
import { Vector3 } from "@babylonjs/core/Maths/math";
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
import { Mesh } from "@babylonjs/core/Meshes/mesh";
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";

The packages where installed with npm successfully under node-modules. Also, vscode did recognize them in the index.ts.

So what is wrong here?

micmei
  • 49
  • 1
  • 6

0 Answers0