ecctrl icon indicating copy to clipboard operation
ecctrl copied to clipboard

Using Typescript: Could not find a declaration file for module 'ecctrl'

Open lighthaus205 opened this issue 2 years ago • 11 comments

Hi, I am excited to use ecctrl, however I am getting the following error when importing the module.

Type error: Could not find a declaration file for module 'ecctrl'. '/Users/konstantinlackner/Dev/konchord-experience-demo/node_modules/ecctrl/dist/Ecctrl.js' implicitly has an 'any' type. Try npm i --save-dev @types/ecctrl if it exists or add a new declaration (.d.ts) file containing declare module 'ecctrl';

I tried npm i --save-dev @types/ecctrl but it is not in the npm registry.

Any idea how to fix this?

Screenshot 2024-01-06 at 12 54 29

lighthaus205 avatar Jan 06 '24 11:01 lighthaus205

I could fix it by simply adding a new file at the root of my project called index.d.ts with the contents: declare module 'ecctrl'

Using NextJS v14.04

lighthaus205 avatar Jan 07 '24 12:01 lighthaus205

I've faced the same issue on Vite project. I've just walked it around with provided code snippet

// @ts-expect-error miss type declaration
import Ecctrl from 'ecctrl'

const Component = () => {
  return (
    <Ecctrl>
      <mesh />
    </Ecctrl>
  )
}

I hope this type declaration issue will be fixed with next patch

myznikovgleb avatar Mar 03 '24 18:03 myznikovgleb

We can add a declaration file to our project to fix this:

// ecctrl.d.ts
declare module "ecctrl" {
  export * from "ecctrl/src/Ecctrl";

  import Ecctrl from "ecctrl/src/Ecctrl";

  export = Ecctrl;
}


That didn't work: lib type constraints conflicted with mine.

Here's enough to get default export working.
// ecctrl.d.ts
declare module "ecctrl" {
  import type { RigidBodyProps, RapierRigidBody } from "@react-three/rapier";

  export interface EcctrlProps extends RigidBodyProps {
    children?: ReactNode;
    debug?: boolean;
    capsuleHalfHeight?: number;
    capsuleRadius?: number;
    floatHeight?: number;
    characterInitDir?: number;
    followLight?: boolean;
    disableFollowCam?: boolean;
    disableFollowCamPos?: { x: number; y: number; z: number };
    disableFollowCamTarget?: { x: number; y: number; z: number };
    // Follow camera setups
    camInitDis?: number;
    camMaxDis?: number;
    camMinDis?: number;
    camInitDir?: { x: number; y: number; z: number };
    camTargetPos?: { x: number; y: number; z: number };
    camMoveSpeed?: number;
    camZoomSpeed?: number;
    camCollision?: boolean;
    camCollisionOffset?: number;
    // Follow light setups
    followLightPos?: { x: number; y: number; z: number };
    // Base control setups
    maxVelLimit?: number;
    turnVelMultiplier?: number;
    turnSpeed?: number;
    sprintMult?: number;
    jumpVel?: number;
    jumpForceToGroundMult?: number;
    slopJumpMult?: number;
    sprintJumpMult?: number;
    airDragMultiplier?: number;
    dragDampingC?: number;
    accDeltaTime?: number;
    rejectVelMult?: number;
    moveImpulsePointY?: number;
    camFollowMult?: number;
    fallingGravityScale?: number;
    fallingMaxVel?: number;
    wakeUpDelay?: number;
    // Floating Ray setups
    rayOriginOffest?: { x: number; y: number; z: number };
    rayHitForgiveness?: number;
    rayLength?: number;
    rayDir?: { x: number; y: number; z: number };
    floatingDis?: number;
    springK?: number;
    dampingC?: number;
    // Slope Ray setups
    showSlopeRayOrigin?: boolean;
    slopeMaxAngle?: number;
    slopeRayOriginOffest?: number;
    slopeRayLength?: number;
    slopeRayDir?: { x: number; y: number; z: number };
    slopeUpExtraForce?: number;
    slopeDownExtraForce?: number;
    // Head Ray setups
    showHeadRayOrigin?: boolean;
    headRayOriginOffest?: number;
    headRayLength?: number;
    headRayDir?: { x: number; y: number; z: number };
    // AutoBalance Force setups
    autoBalance?: boolean;
    autoBalanceSpringK?: number;
    autoBalanceDampingC?: number;
    autoBalanceSpringOnY?: number;
    autoBalanceDampingOnY?: number;
    // Animation temporary setups
    animated?: boolean;
    // Mode setups
    mode?: string;
    // Controller setups
    controllerKeys?: {
      forward?: number;
      backward?: number;
      leftward?: number;
      rightward?: number;
      jump?: number;
      action1?: number;
      action2?: number;
      action3?: number;
      action4?: number;
    };
    // Other rigibody props from parent
    props?: RigidBodyProps;
  }

  const Ecctrl: React.ForwardRefExoticComponent<EcctrlProps & React.RefAttributes<RapierRigidBody>>;

  export = Ecctrl;

}

rob-myers avatar Mar 04 '24 15:03 rob-myers

After some research I've found a last version of the package that has a type declaration file. It's 1.0.58. And it seems like all versions after 1.0.58 does not have a type declaration file. Check out npm link https://www.npmjs.com/package/ecctrl/v/1.0.59?activeTab=code.

I guess it is a kind of a ci problem. Because locally I can build the package with a type declaration file (current main) running a npm run build command.

@ErdongChen-Andrew Sorry for disturbance. Maybe this information will be helpfull for you. Btw do you have time to check what is broken?

myznikovgleb avatar Mar 07 '24 22:03 myznikovgleb

Thank you @myznikovgleb ! My bad! In version 1.0.67, a type declaration file should be included. Thanks again for pointing this out!

ErdongChen-Andrew avatar Mar 07 '24 23:03 ErdongChen-Andrew

Is the declaration file just meant to say export * from '../src/Ecctrl.tsx'? That's what I see in my node_modules with 1.0.67.

This seems to cause TypeScript to attempt compilation of the Ecctrl.tsx file but it won't work if that file cannot be compiled against the tsconfig.json file used in my project. I was only able to get it to work by cloning this repo and running tsc to get the actual declaration files and the depending on the cloned repo instead.

sepbot avatar Mar 14 '24 21:03 sepbot

Is the declaration file just meant to say export * from '../src/Ecctrl.tsx'? That's what I see in my node_modules with 1.0.67.

This seems to cause TypeScript to attempt compilation of the Ecctrl.tsx file but it won't work if that file cannot be compiled against the tsconfig.json file used in my project. I was only able to get it to work by cloning this repo and running tsc to get the actual declaration files and the depending on the cloned repo instead.

🤔 Emm, not sure about the problem. 1.0.67 was able to fix the declaration issue in my test project.

ErdongChen-Andrew avatar Mar 14 '24 23:03 ErdongChen-Andrew

Still having this issue on latest version, any news?

jeffrhap avatar Mar 31 '24 12:03 jeffrhap

Still having this issue on latest version, any news?

Just made some updates, try on v1.0.75. Let me know if it works.

ErdongChen-Andrew avatar Mar 31 '24 23:03 ErdongChen-Andrew

I still have this issue with "ecctrl": "^1.0.77". I've tried the suggested type declarations, but they didn't work.

Indeed, the d.ts file is missing in the node_modules:

image

I've cloned this repo and tested the build script and it generates the type definitions. Unfortunately it seems like a CI bug indeed so I can't really help with a PR.

tiborsaas avatar May 11 '24 15:05 tiborsaas

My bad, @tiborsaas. version 1.0.78 should include the d.ts file. Missing it in 1.0.76 and 1.0.77 😅

ErdongChen-Andrew avatar May 11 '24 18:05 ErdongChen-Andrew