Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: performance is not defined #4

Open
DanielHZhang opened this issue Nov 3, 2020 · 3 comments
Open

ReferenceError: performance is not defined #4

DanielHZhang opened this issue Nov 3, 2020 · 3 comments

Comments

@DanielHZhang
Copy link

This seems to be originating from the b2Timer class and its usage of performance.now() when @box2d/core is executed from nodejs. A simple fix would be to synchronously require the performance module when running in node>=8.5.

export const performance =
    typeof globalThis.window !== "undefined"
        ? window.performance
        : (require("perf_hooks") as typeof import("perf_hooks").performance;

However, this leads to Module "perf_hooks" not found error when bundling with webpack, unless {externals: {perf_hooks: 'empty'}} is set in the config.

@Lusito
Copy link
Owner

Lusito commented Nov 7, 2020

Check out https://github.com/Lusito/box2d.ts/blob/master/packages/benchmark/src/cli/index.ts to see how I fix it in the benchmarks.

Out of curiousity: Are you using box2d in node.js other than for benchmarking?

@DanielHZhang
Copy link
Author

I'm using box2d server-side as part of my authoritative game server architecture. Clients run box2d locally in their browser and send their inputs to the nodejs server. The server is also running box2d in a worker thread, which computes the results of received inputs, then sends the updated world state back to each client.

@dongshimou
Copy link

same problem when i use node v14.x.
solve this problem with node v16.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants