Missing Dependencies

Annoyingly, a demo no longer works. I then upgraded to the current Needle version. The errors remain. Can you please help me solve the problem? Thanks.




Hi Matthias,

The errors you’re encountering related to “Missing Dependencies” can often arise after updates if the project references were not properly updated. Here are a few steps to help troubleshoot and resolve your issues:

  1. Update Dependencies: Ensure all dependencies referenced in package.json are resolved correctly. Check that all npm definitions are valid and exist in your project. Missing npm definitions can lead to errors.

  2. Check for Existing GUIDs: If any packages are missing, they might not have the correct GUID associated with them. Look for missing dependencies in your ExportInfo object and make sure their GUIDs are set appropriately.

  3. Installation: It’s important to run npm install to ensure all packages are installed correctly. You may need to clean the node_modules directory and run npm install again if there was any corruption.

  4. Error Logs: Check the Console logs for specific errors. If there are messages indicating a failed installation or missing paths, these can guide you on what needs to be fixed.

  5. Package Paths: If you’ve moved any package files or renamed folders, make sure your project references point to the new locations. Use the functions provided in your files (like Install methods on dependencies) to update paths accordingly (see the documentation) (see the documentation).

In the provided code snippets, functions like Install and EnsureDependenciesAreAddedToPackageJson are essential for checking and installing missing packages.

If the problem persists even after these checks, providing more specific error messages or the content of the package.json file could help in diagnosing the issue further.

Let me know how it goes, and if you need further assistance!

1 replies left - Get a PRO license for more AI replies.
thread_iYEMAglmYkAyp1IwuEVqIhtE
Reply to this message to continue the conversation

Hello Matthias,

can you share more info. What does the browser console error show?

Can you share the RBChangePositionOnClick script / imports? The error reads like you tried to import a script from a path/directory that is not exported.

Ah, ich sehe da einen Fehler im Script. Zeile 141

import { ActionBuilder, BehaviorModel, Behaviour, GameObject, IPointerClickHandler, ObjectRaycaster, PointerEventData, TriggerBuilder, UsdzBehaviour, getWorldPosition, getWorldQuaternion, getWorldScale, isDevEnvironment, serializable, setWorldPosition, setWorldQuaternion, setWorldScale } from "@needle-tools/engine";
import { Space } from "@needle-tools/engine/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder";
import { Object3D, Vector3, Quaternion, Raycaster } from "three";

// Documentation → https://docs.needle.tools/scripting

function ensureRaycaster(obj: GameObject) {
    if (!obj) return;
    if (!obj.getComponentInParent(Raycaster)) {
        if (isDevEnvironment()) console.warn("Create Raycaster on " + obj.name + " because no raycaster was found in the hierarchy")
        obj.addNewComponent(ObjectRaycaster);
    }
}

export class RRChangePositionOnClick extends Behaviour implements UsdzBehaviour  {

        @serializable(Object3D)
        object?: Object3D;
    
        @serializable(Object3D)
        target?: Object3D;
    
        @serializable()
        duration: number = 1;
    
        @serializable()
        relativeMotion: boolean = false;
    
        private coroutine: Generator | null = null;
    
        private targetPos = new Vector3();
        private targetRot = new Quaternion();
        private targetScale = new Vector3();
    
        start(): void {
            ensureRaycaster(this.gameObject);
        }
    
        onClicked() {
            if (this.coroutine) this.stopCoroutine(this.coroutine);
            if (!this.relativeMotion)
                this.coroutine = this.startCoroutine(this.moveToTarget());
            else
                this.coroutine = this.startCoroutine(this.moveRelative());
        }
    
        private *moveToTarget() {
    
            if (!this.target || !this.object) return;
    
            const thisPos = getWorldPosition(this.object).clone();
            const targetPos = getWorldPosition(this.target).clone();
    
            const thisRot = getWorldQuaternion(this.object).clone();
            const targetRot = getWorldQuaternion(this.target).clone();
    
            const thisScale = getWorldScale(this.object).clone();
            const targetScale = getWorldScale(this.target).clone();
    
            const dist = thisPos.distanceTo(targetPos);
            const rotDist = thisRot.angleTo(targetRot);
            const scaleDist = thisScale.distanceTo(targetScale);
    
            if (dist < 0.01 && rotDist < 0.01 && scaleDist < 0.01) {
                setWorldPosition(this.object, targetPos);
                setWorldQuaternion(this.object, targetRot);
                setWorldScale(this.object, targetScale);
                this.coroutine = null;
                return;
            }
    
            let t01 = 0;
            let eased = 0;
            while (t01 < 1) {
    
                t01 += this.context.time.deltaTime / this.duration;
                if (t01 > 1) t01 = 1;
    
                // apply ease-in-out
                // https://easings.net/
                eased = t01 < 0.5 ? 4 * t01 * t01 * t01 : 1 - Math.pow(-2 * t01 + 2, 3) / 2;
    
                this.targetPos.lerpVectors(thisPos, targetPos, eased);
                this.targetRot.slerpQuaternions(thisRot, targetRot, eased);
                this.targetScale.lerpVectors(thisScale, targetScale, eased);
    
                setWorldPosition(this.object, this.targetPos);
                setWorldQuaternion(this.object, this.targetRot);
                setWorldScale(this.object, this.targetScale);
    
                yield;
            }
    
            this.coroutine = null;
        }
    
        private *moveRelative() {
    
            if (!this.target || !this.object) return;
    
            const thisPos = this.object.position.clone();
            const thisRot = this.object.quaternion.clone();
            const thisScale = this.object.scale.clone();
    
            const posOffset = this.target.position.clone();
            const rotOffset = this.target.quaternion.clone();
            const scaleOffset = this.target.scale.clone();
    
            // convert into right space
            posOffset.applyQuaternion(this.object.quaternion);
    
            this.targetPos.copy(this.object.position).add(posOffset);
            this.targetRot.copy(this.object.quaternion).multiply(rotOffset);
            this.targetScale.copy(this.object.scale).multiply(scaleOffset);
    
            let t01 = 0;
            let eased = 0;
            while (t01 < 1) {
    
                t01 += this.context.time.deltaTime / this.duration;
                if (t01 > 1) t01 = 1;
    
                // apply ease-in-out
                // https://easings.net/
                eased = t01 < 0.5 ? 4 * t01 * t01 * t01 : 1 - Math.pow(-2 * t01 + 2, 3) / 2;
    
                this.object.position.lerpVectors(thisPos, this.targetPos, eased);
                this.object.quaternion.slerpQuaternions(thisRot, this.targetRot, eased);
                this.object.scale.lerpVectors(thisScale, this.targetScale, eased);
    
                yield;
            }
    
            this.coroutine = null;
        }
    
        beforeCreateDocument(ext) {
            if (this.target && this.object && this.gameObject) {
                const moveForward = new BehaviorModel("Move to " + this.target?.name,
                    TriggerBuilder.tapTrigger(this.gameObject),
                    ActionBuilder.transformAction(this.object, this.target, this.duration, this.relativeMotion ? Space.Relative : Space.Absolute),
                );
                ext.addBehavior(moveForward);
            }
        }
    }

This import is not valid:

import { Space } from "@needle-tools/engine/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder";

Importing from a directory that isnt exported. Can you try changing it to ... from "@needle-tools/engine" ?

If the type is not exported you could as a quick workaround add this to your script at the top and remove the import:

type Space = "relative" | "absolute";

Thanks. I removed the script because I’m not using it in this demo. Now everything functions as it should.

1 Like

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.