'sync-ammo' causes compilation errors even with physics disabled
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 528
- Forks
- 60
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
I have a project that is disabling physics explicitly with <Application usePhysics={false}> (even though it's supposed to be disabled by default). When I compile my project, I'm getting this error:
WARNING in ./node_modules/@playcanvas/react/dist/contexts/physics-context.js 48:39-58
Module not found: Error: Can't resolve 'sync-ammo' in '.../node_modules/@playcanvas/react/dist/contexts'
I'm on @playcanvas/react version 0.11.3 and playcanvas engine version 2.15.1.
Within @playcanvas/react/dist/contexts/physics-context.js, I do see this:
export const PhysicsProvider = ({ children, enabled, app }) => {
const [isPhysicsLoaded, setIsPhysicsLoaded] = useState(false);
const [physicsError, setPhysicsError] = useState(null);
useEffect(() => {
if (!enabled) {
setIsPhysicsLoaded(false);
setPhysicsError(null);
return;
}
const loadPhysics = async () => {
try {
// @ts-expect-error The PC Physics system expects a global Ammo instance
if (!globalThis.Ammo) {
const Ammo = await import('sync-ammo');
// @ts-expect-error The PC Physics system expects a global Ammo instance
globalThis.Ammo = Ammo.default;
}
and within Application.js.map I see this:
<PhysicsProvider enabled={usePhysics} app={app}>
so I'm not sure what could be causing this since enabled is false.
For now I've got a webpack ignore plugin configured for sync-ammo as a workaround, so this isn't a major issue, but I wanted to post for visibility in case others are running into this.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the warning with @playcanvas/react 0.11.3 and usePhysics={false}, then inspect dist/contexts/physics-context.js and the Application.js.map entry mentioned in the report. Confirm the fix by compiling without the webpack ignore plugin and verifying that disabled physics no longer requires sync-ammo.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript, webpack
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100