Skip to content

fix: compile console plugin.ts to JS for Node.js runtime compatibility#509

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-err-module-not-found
Feb 14, 2026
Merged

fix: compile console plugin.ts to JS for Node.js runtime compatibility#509
hotlong merged 3 commits intomainfrom
copilot/fix-err-module-not-found

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 14, 2026

@object-ui/console ships "main": "./plugin.ts" — a raw TypeScript entry point. Downstream projects (e.g. hotcrm on Vercel) that keep node_modules external during bundling hit ERR_MODULE_NOT_FOUND at runtime because Node.js cannot execute .ts files natively.

Changes

  • tsconfig.plugin.json — New tsconfig that compiles plugin.tsplugin.js + plugin.d.ts with nodenext module resolution for Node.js runtime compatibility
  • package.json — Entry points now reference compiled output:
    • main./plugin.js, types./plugin.d.ts
    • exports updated with proper types/import/default conditions
    • build:plugin script added, chained into build and build:vercel
    • plugin.js and plugin.d.ts added to files
  • .gitignore — Excludes generated plugin.js / plugin.d.ts

Before/After

// Before — Node.js fails at runtime
{ "main": "./plugin.ts" }

// After — works in any Node.js environment
{ "main": "./plugin.js", "types": "./plugin.d.ts" }

plugin.ts source is still included in the published package for reference. Monorepo-internal relative imports (../../apps/console/plugin) continue to resolve to the .ts source via TypeScript.

Original prompt

fix 下游hotcrm项目集成console后报错, Investigate the ERR_MODULE_NOT_FOUND error for @object-ui/console/plugin.ts
Root cause: @object-ui/console npm package has "main": "./plugin.ts" (TypeScript entry point). Vercel's @vercel/node keeps node_modules external during bundling, so at runtime Node.js tries to import plugin.ts directly — but Node.js cannot execute TypeScript files natively.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui Error Error Feb 14, 2026 0:40am
objectui-demo Error Error Feb 14, 2026 0:40am
objectui-storybook Error Error Feb 14, 2026 0:40am

Request Review

The @object-ui/console package had "main": "./plugin.ts" pointing to raw
TypeScript. Downstream projects (e.g. hotcrm on Vercel) that keep
node_modules external during bundling would fail at runtime with
ERR_MODULE_NOT_FOUND because Node.js cannot execute .ts files natively.

Changes:
- Add tsconfig.plugin.json to compile plugin.ts → plugin.js + plugin.d.ts
- Add build:plugin script, integrated into build and build:vercel
- Update package.json main/exports/types to point to compiled .js/.d.ts
- Add plugin.js and plugin.d.ts to .gitignore (build artifacts)
- Keep plugin.ts in published files for source reference

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Address code review feedback: use nodenext (not bundler) module resolution
since plugin.js runs in Node.js at runtime, not in a bundler.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ERR_MODULE_NOT_FOUND error in hotcrm integration fix: compile console plugin.ts to JS for Node.js runtime compatibility Feb 14, 2026
Copilot AI requested a review from hotlong February 14, 2026 12:40
@hotlong hotlong marked this pull request as ready for review February 14, 2026 12:46
Copilot AI review requested due to automatic review settings February 14, 2026 12:46
@hotlong hotlong merged commit dec7e95 into main Feb 14, 2026
1 of 4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a runtime compatibility issue where @object-ui/console was shipping raw TypeScript source (plugin.ts) as its entry point, causing ERR_MODULE_NOT_FOUND errors in production environments like Vercel that keep node_modules external during bundling. Node.js cannot execute TypeScript files natively, so the plugin must be compiled to JavaScript before publication.

Changes:

  • Added dedicated TypeScript compilation configuration for the plugin entry point
  • Updated package.json to reference compiled JavaScript output while preserving TypeScript source for reference
  • Configured build pipeline to generate plugin.js and plugin.d.ts during the build process

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/console/tsconfig.plugin.json New TypeScript configuration for compiling plugin.ts to Node.js-compatible JavaScript with nodenext module resolution
apps/console/package.json Updated entry points to reference compiled plugin.js, added build:plugin script, included compiled outputs in published files
apps/console/.gitignore Excludes generated plugin.js and plugin.d.ts from version control

"declaration": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tsconfig is missing the outDir compiler option. Without it, TypeScript will emit the compiled plugin.js and plugin.d.ts files in the same directory as the source file (the root of apps/console/), which is the desired behavior based on the .gitignore entries. However, it's a best practice to explicitly specify outDir: "." for clarity, and to ensure the configuration is self-documenting. Consider adding "outDir": "." to the compilerOptions.

Suggested change
"esModuleInterop": true
"esModuleInterop": true,
"outDir": "."

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

3 participants