Skip to content

'sync-ammo' causes compilation errors even with physics disabled #307

@ice1080

Description

@ice1080

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions