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

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

Open
lighthaus205 opened this issue Jan 6, 2024 · 11 comments

Comments

@lighthaus205
Copy link

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
Copy link
Author

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

@myznikovgleb
Copy link

myznikovgleb commented Mar 3, 2024

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

@rob-myers
Copy link

rob-myers commented Mar 4, 2024

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;

}

@myznikovgleb
Copy link

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?

@ErdongChen-Andrew
Copy link
Member

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

@sepbot
Copy link

sepbot commented Mar 14, 2024

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.

@ErdongChen-Andrew
Copy link
Member

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.

@jeffrhap
Copy link

Still having this issue on latest version, any news?

@ErdongChen-Andrew
Copy link
Member

Still having this issue on latest version, any news?

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

@tiborsaas
Copy link

tiborsaas commented May 11, 2024

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.

@ErdongChen-Andrew
Copy link
Member

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

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

7 participants