Get an error that says `[gea-plugin] Could not resolve @geajs/core compiler runtime` when developing with Vite
- Dominant language
- JavaScript
- Stars
- 1.2k
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
While developing with Geajs in Vite, I encountered this error:
```text
4:33:31 PM [vite] (client) Pre-transform error: [gea-plugin] Could not resolve @geajs/core compiler runtime
4:33:31 PM [vite] Internal server error: [gea-plugin] Could not resolve @geajs/core compiler runtime
at LoadPluginContext.load (file:///home/korphere/projects/geasc/ecosystem/node_modules/.pnpm/@geajs+vite-plugin@1.4.1_vite@8.2.2_@types+node@26.2.0_esbuild@0.28.2_/node_modules/@geajs/vite-plugin/dist/index.mjs:8272:11)
at async EnvironmentPluginContainer.load (file:///home/korphere/projects/geasc/ecosystem/node_modules/.pnpm/vite@8.2.2_@types+node@26.2.0_esbuild@0.28.2/node_modules/vite/dist/node/chunks/node.js:30890:19)
at async loadAndTransform (file:///home/korphere/projects/geasc/ecosystem/node_modules/.pnpm/vite@8.2.2_@types+node@26.2.0_esbuild@0.28.2/node_modules/vite/dist/node/chunks/node.js:20624:21)
at async viteTransformMiddleware (file:///home/korphere/projects/geasc/ecosystem/node_modules/.pnpm/vite@8.2.2_@types+node@26.2.0_esbuild@0.28.2/node_modules/vite/dist/node/chunks/node.js:25205:20)
4:33:31 PM [vite] (client) Pre-transform error: [gea-plugin] Could not resolve @geajs/core compiler runtime
```
Upon investigating the cause of this issue, I discovered that a function called `compilerRuntimePathFromCoreEntry` in the source code of `@geajs/vite-plugin` was the culprit.
```js
function compilerRuntimePathFromCoreEntry(entry) {
const clean = entry.split("?")[0];
if (clean.endsWith("/src/index.ts")) return clean.slice(0, -13) + "/src/compiler-runtime.ts";
if (clean.endsWith("/dist/index.mjs")) return clean.slice(0, -15) + "/dist/compiler-runtime.mjs";
return null;
}
```
As such, this implementation assumes you know the actual directory structure of the package—specifically, that `compiler-runtime.mjs` is located next to the actual file path of `@geajs/core`. However, Vite has a pre-bundling feature. Because multiple files are bundled into a single file, a situation can arise where the plugin searches for the compiler runtime based on the directory structure, only to find that the file does not exist at that path. While it would be ideal for the plugin to support Vite’s pre-bundling feature, users can currently work around this issue. Please take a look at the following `vite.config.ts`:
```ts
import { defineConfig } from 'vite'
import { geaPlugin } from '@geajs/vite-plugin'
export default defineConfig({
plugins: [geaPlugin()],
})
```
In this case, Vite's pre-bundling will take effect, causing that issue. The solution is to exclude `@geajs/core` from Vite's optimization, as shown below:
```ts
import { defineConfig } from 'vite'
import { geaPlugin } from '@geajs/vite-plugin'
export default defineConfig({
plugins: [geaPlugin()],
optimizeDeps: {
exclude: ['@geajs/core'],
},
})
```
This easily resolves the issue. However, to prevent users from getting confused, the plugin should support pre-bundle optimization in the future.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading compilerRuntimePathFromCoreEntry in @geajs/vite-plugin and reproduce the failure with the issue's vite.config.ts, first comparing normal loading with optimizeDeps excluding @geajs/core. Done means the plugin supports Vite pre-bundling without the reported compiler-runtime resolution error, while preserving the documented workaround behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100