1

index.ts

import { Engine } from '@babylonjs/core/Engine/engine';

[tsl] ERROR in ~/Documents/babylon1/src/index.ts(1,24)
  TS2307: Cannot find module '@babylonjs/core/Engines/engine'.

I've followed the steps on the Babylon documentation pages, and the troubleshooting notes at https://doc.babylonjs.com/features/npm_support#error-ts2307-cannot-find-module-babylonjs-or-other-modules. I've added "babylonjs" to tscong.json, but I'm still getting the "Cannot find module @babylonjs/core" error.

package.json

"devDependencies": {
    "@babylonjs/core": "^4.0.3",
    "ts-loader": "^6.2.1",
    "typescript": "^3.7.4",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.10.1"
},
"dependencies": {
  "babylonjs": "^4.0.3"
}

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./dist",
        "sourceMap": true,
        "noImplicitAny": true,
        "strictNullChecks": false,
        "module": "es6",
        "target": "es6",
        "types": [
            "babylonjs"
        ]
    }
}

I did npm install just to make sure nothing is missing.

1
  • 1
    I got it to compile by doing npm install -D @types/babylonjs, and changing the import to babylonjs. It's not ideal, because it imports the entire 2.5MB library, rather than individual modules, but it works. Commented Dec 31, 2019 at 21:06

1 Answer 1

1

The following setup works. The @babylonjs/core/... imports resolve correctly, and webpack-dev-server builds and reloads automatically.

package.json

"devDependencies": {
  "@babylonjs/core": "^4.0.3",
  "ts-loader": "^6.2.1",
  "typescript": "^3.7.4",
  "webpack": "^4.41.5",
  "webpack-cli": "^3.3.10",
  "webpack-dev-server": "^3.10.1"
},
"dependencies": {}

tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "module": "esNext",
    "target": "es6",
    "moduleResolution": "node"
  }
}

NOTE: types: ["babylonjs"] doesn't seem to be necessary

webpack.config.js

module: {
  rules: [
    {
      test: /\.tsx?$/,
      use: 'ts-loader',
      exclude: /node_modules/
    },
  ],
},
resolve: {
  extensions: [ '.tsx', '.ts', '.js' ],
},
output: {
  filename: 'bundle.js'
},
devServer: {
  contentBase: path.join(__dirname, 'dist'),
  compress: true,
  hot: true
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.