Skip to content

[BUG] [v0.0.7] cortex plugin new --typescript package.json missing "type": "module" while tsconfig.json emits ESNext modules — generated dist/index.js fails to load in Node #48497

@AnticsDecoded

Description

@AnticsDecoded

Project

ide

Description

The TypeScript plugin scaffolder produces an inconsistent module system configuration that breaks the generated build at runtime.

The generated tsconfig.json sets:

{
    "compilerOptions": {
        "target": "ES2020",
        "module": "ESNext",
        "moduleResolution": "node",
        ...
        "outDir": "./dist"
    }
}

The generated src/index.ts uses ES module syntax throughout: export const PLUGIN_ID = "...", export function init(): number {...}, export function shutdown(): number {...}, export function cmd_example(args: string[]): number {...}.

The generated package.json does NOT contain "type": "module":

{
    "name": "my-ts-plugin",
    "version": "0.1.0",
    "description": "...",
    "main": "dist/index.js",
    "scripts": {
        "build": "tsc",
        "watch": "tsc --watch"
    },
    "devDependencies": {
        "typescript": "^5.0.0"
    }
}

When npm run build runs, tsc honours "module": "ESNext" and emits dist/index.js containing real export statements. But because package.json lacks "type": "module", Node interprets the .js extension as CommonJS and the very first export token throws SyntaxError: Unexpected token 'export' whenever the host tries to load the plugin. The scaffolded TypeScript plugin is not actually loadable as-is.

Error Message

$ node dist/index.js
file:///.../my-ts-plugin/dist/index.js:2
export const PLUGIN_ID = "my-ts-plugin";
^^^^^^

SyntaxError: Unexpected token 'export'

Debug Logs

System Information

Windows 11, cortex v0.0.7, Node.js v20.x

Screenshots

package.json missing type module

Steps to Reproduce

  1. cortex plugin new my-ts-plugin --typescript
  2. cd my-ts-plugin && npm install && npm run build
  3. node dist/index.js (or any host that loads dist/index.js) → SyntaxError: Unexpected token 'export'
  4. Inspect the three files: tsconfig.json says "module": "ESNext", src/index.ts uses ESM export syntax, package.json has no "type" key

Expected Behavior

The generated package.json should include "type": "module" so that the ESM-syntax dist/index.js produced by tsc is correctly treated as a Node ES module. Alternatively, tsconfig.json should set "module": "CommonJS" to match the implicit Node interpretation. Either choice is fine, but the three files must agree.

Actual Behavior

tsconfig.json and src/index.ts agree on ES modules; package.json does not. tsc produces ESM-syntax JavaScript that Node refuses to execute. The scaffolded TypeScript plugin is broken out of the box and cannot be loaded by any standard Node-based plugin host.

Additional Context

This is a functional bug: the scaffold does not just have cosmetic issues — it produces a build artifact that fails at the very first load attempt. Two trivial fixes exist (add "type": "module" to package.json, OR change tsconfig.json "module" from "ESNext" to "CommonJS"); the scaffolder picks neither and ships an inconsistent template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideIssues related to IDEvalidValid issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions