Search code examples
typescriptbox2d

Cannot run Testbed with TypeScript and Parcel. Error: planck.testbed is not a function


Is it possible to use Testbed with Parcel? I made a simple example in TypeScript on Sandbox: https://codesandbox.io/s/planckjs-testbed-ts-n4imh4?file=/src/index.ts I have this error: planck.testbed is not a function

import * as planck from "planck-js";

planck.testbed(function (t)
{
    // Create a world
    const world = planck.World();

    console.log(world.getGravity());

    // Make sure you return the world
    return world;
});

package.json

{
  "name": "testbed-ts",
  "version": "1.0.0",
  "description": "",
  "main": "public/js/bundle.js",
  "targets": {
    "main": {
       "includeNodeModules": true
    }
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "del_files": "del /f /q /s .\\public\\js\\*.*",
    "dev": "npm run del_files && parcel watch src/main.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "gl-matrix": "^3.4.3",
    "planck-js": "^0.3.31"
  },
  "devDependencies": {
    "@types/gl-matrix": "^3.2.0"
  }
}

Solution

  • import * as planck from "./node_modules/planck-js/dist/planck-with-testbed";
    

    Instead of:

    import * as planck from "planck-js";