Skip to content

Support for ESNext module imports in Godot-TS #234

Description

@jmservier

I’m trying to use Godot-TS with a pure ESNext setup (no CommonJS), but I can’t find any examples demonstrating this configuration. When I attempt to import the godot namespace, I get an error saying that the module has no exported member godot.

Reproduction Steps:

  1. Create a new GodotJS + TypeScript project.
  2. Generate a godot.d.ts at the project root via the Godot editor:
// godot.d.ts
export namespace godot {
  export type GodotClass = new () => godot.Object;
  export class Object {}
  export class Node extends godot.Object {
    _ready(): void;
  }
  export namespace Node {}
}
  1. Configure tsconfig.json as follows:
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "rootDir": ".",
    "outDir": "dist",
    "declaration": true,
    "declarationDir": "typings",
    "isolatedModules": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "experimentalDecorators": true,
    "incremental": true,
    "tsBuildInfoFile": ".godot/.tsbuildinfo",
    "baseUrl": "."
  },
  "include": [
    "src",
    "godot.d.ts",
    "typings"
  ],
  "exclude": [
    "lib.dom.d.ts",
    "node_modules",
    "dist"
  ],
  "types": ["godot.d.ts"]
}
  1. In a TypeScript file:
    import { godot } from "godot";
  1. Build or run the project.

Actual Behavior:

Module '"godot"' has no exported member 'godot'.

Expected Behavior:
The godot namespace should be available as an ES module import, matching the declarations in godot.d.ts.

Notes / Questions:

  • Are there existing examples or recommended settings for using Godot-TS with "module": "ESNext"?
    
  • Should the declarations in `godot.d.ts` be modified (e.g. use export default godot, or a different module mapping) to support ESM?
    
  • Is there a mapping or alias configuration needed in `tsconfig.json` (e.g. paths) to make import { godot } from "godot" work?
    

Any guidance or example repository demonstrating a pure ESNext import setup would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions