fix: compile console plugin.ts to JS for Node.js runtime compatibility#509
fix: compile console plugin.ts to JS for Node.js runtime compatibility#509
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| "esModuleInterop": true | |
| "esModuleInterop": true, | |
| "outDir": "." |
@object-ui/consoleships"main": "./plugin.ts"— a raw TypeScript entry point. Downstream projects (e.g. hotcrm on Vercel) that keepnode_modulesexternal during bundling hitERR_MODULE_NOT_FOUNDat runtime because Node.js cannot execute.tsfiles natively.Changes
tsconfig.plugin.json— New tsconfig that compilesplugin.ts→plugin.js+plugin.d.tswithnodenextmodule resolution for Node.js runtime compatibilitypackage.json— Entry points now reference compiled output:main→./plugin.js,types→./plugin.d.tsexportsupdated with propertypes/import/defaultconditionsbuild:pluginscript added, chained intobuildandbuild:vercelplugin.jsandplugin.d.tsadded tofiles.gitignore— Excludes generatedplugin.js/plugin.d.tsBefore/After
plugin.tssource is still included in the published package for reference. Monorepo-internal relative imports (../../apps/console/plugin) continue to resolve to the.tssource via TypeScript.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.