[create-twenty-app] Use vite config lib#16273
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| output: [ | ||
| { | ||
| format: 'es', | ||
| entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'), | ||
| }, |
There was a problem hiding this comment.
Bug: ES module output cli.mjs uses __dirname, which is undefined in ESM, causing ReferenceError on import.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The vite.config.ts generates an ES module output (cli.mjs) that includes references to __dirname. In ES module contexts, __dirname is not defined, leading to a ReferenceError: __dirname is not defined when cli.mjs is imported. This makes the ES module version of the package unusable for consumers using ES module syntax, despite the CommonJS version working correctly.
💡 Suggested Fix
Configure Vite/Rollup to either polyfill __dirname for ES module output, or use import.meta.url for path resolution in cli.mjs and app-template.ts. Alternatively, remove the ES module export if it's not intended for ES module consumption.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/create-twenty-app/vite.config.ts#L68-L72
Potential issue: The `vite.config.ts` generates an ES module output (`cli.mjs`) that
includes references to `__dirname`. In ES module contexts, `__dirname` is not defined,
leading to a `ReferenceError: __dirname is not defined` when `cli.mjs` is imported. This
makes the ES module version of the package unusable for consumers using ES module
syntax, despite the CommonJS version working correctly.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5129230
There was a problem hiding this comment.
Should use import.meta.dirname
Greptile OverviewGreptile SummaryMigrates Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Build as Build System
participant Vite as Vite
participant FS as File System
participant CLI as CLI Runtime
Dev->>Build: npm run build
Build->>Vite: Execute vite build
Note over Vite: Compile TypeScript sources
Vite->>Vite: Bundle src/cli.ts → dist/cli.cjs + dist/cli.mjs
Vite->>Vite: Apply tsconfigPaths plugin
Vite->>Vite: Generate types with dts plugin
Note over Vite: Execute copy-assets plugin
Vite->>FS: Copy src/constants/base-application
FS->>FS: Create dist/constants/base-application
Note over Vite: Build complete
Dev->>CLI: node dist/cli.cjs [directory]
CLI->>CLI: Initialize commander program
CLI->>FS: Read package.json from __dirname/../package.json
CLI->>CLI: Execute CreateAppCommand
CLI->>FS: Copy from __dirname/./constants/base-application
FS->>FS: Create new app directory with template
CLI->>Dev: App created successfully
|
There was a problem hiding this comment.
Additional Comments (1)
-
packages/create-twenty-app/project.json, line 24 (link)logic: The build output changed from
cli.jstocli.cjs, but the start command still references the old filename
9 files reviewed, 3 comments
Followup #16258