build: an extensionless "./app" import outside the views bundles app.tsx while TypeScript checks app.ts

Open
#723 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
26/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, typescript

Research direction

Start by reading resolveSolidAotModel in microts/compiler/aot-solid-browser.ts (lines 120–127) and resolveImport in tools/build.ts (251–266), and compare which extension each pass prefers for a non-component importer. Reproduce with the app.ts/app.tsx pair from the report, run bun tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb, then inspect dist/repro.js for the folded undefined. Done when an extensionless ./app resolves to app.ts in both passes, or the ambiguous specifier is reported as an error.

Written by the indexing model from the issue text.

Description

bug

Version

PocketJS v0.17.0 (83c6cac9, current main). macOS 27.2 arm64, Bun 1.4.2.

Repro

An aot: true, model: "compiled" application whose entry also reads the root model, for example to connect host callbacks.

pocket.host.json, pocket.host.config.ts
{
  "format": "pocket-host/2",
  "id": "repro-esp32s3",
  "platform": "esp-idf",
  "form": "takeover",
  "cadences": [30],
  "display": {
    "logicalViewports": [[240, 240]],
    "presentations": ["native"],
    "rasterDensity": 1,
    "animation": "repaint"
  },
  "panel": { "primary": [240, 240] },
  "capabilities": ["input.buttons", "text.glyphs.baked"]
}
// pocket.host.config.ts
import { defineHostConfig } from "@pocketjs/framework/host-config";

export default defineHostConfig({
  host: "./pocket.host.json",
  app: {
    id: "dev.example.repro",
    title: "Repro",
    version: "0.1.0",
    entry: "main.tsx",
    output: "repro",
    framework: "solid",
    viewport: { logical: [240, 240], presentation: "native" },
    features: ["input.buttons", "text.glyphs.baked"],
    aot: true,
    model: "compiled",
  },
});
// app.ts
import { createSignal } from "solid-js";
import type { i32 } from "@pocketjs/framework/solid/std";
export const [count, setCount] = createSignal<i32>(0);
export function hostReset(): void {
  setCount(0);
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import { count, setCount } from "./app";

export default function App() {
  return (
    <View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => setCount(count() + 1)}>
      <Text class="text-lg text-slate-900">Count {count()}</Text>
    </View>
  );
}
// main.tsx
import { mount } from "@pocketjs/framework/solid";
import App from "./app.tsx";
import * as model from "./app";

mount(() => {
  console.log(`hostReset: ${typeof model.hostReset}`);
  return <App />;
});
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb

Actual

The type check and the build pass:

✓ TypeScript (62 app module(s))
✓ Bundle: out/app.pkb

dist/repro.js resolved ./app to app.tsx, which has no hostReset, and folded the member to undefined:

  // main.tsx
  mount(() => {
    console.log(`hostReset: ${typeof undefined}`);
    return createComponent2(App, {});
  });

With a named import in main.tsx (import { hostReset } from "./app";) the type check passes and the bundler stops:

error: No matching export in "app.tsx" for import "hostReset"

Expected

The bundle uses the module the type check used. The MicroTS docs name the extensionless path as the model ("Counter.tsx imports its model from ./Counter", microts-solid.md, "Files and ownership"), so ./app resolves to app.ts for every importer in the application, or the build reports the ambiguous specifier.

Cause

resolveSolidAotModel (microts/compiler/aot-solid-browser.ts:120–127) prefers the model only when the importer is a .tsx component of the AOT graph. main.tsx is the entry, not a component, so the request falls through to Bun's resolver, which tries .tsx before .ts. TypeScript tries .ts first. Pass 1 has the same split (resolveImport, tools/build.ts:251–266). A .ts module outside the view graph resolves the same way: a bridge.ts with import * as model from "./app", imported by main.tsx, also bundles typeof model.hostReset as typeof undefined.

Workaround

Write the extension: import * as model from "./app.ts";. The bundle then uses the compiled model module.

Dominant language
TypeScript
Stars
1.6k
Forks
88
PR merge metrics
No merged PRs in 30d

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pocket-stack/pocketjs

All issues in pocket-stack/pocketjs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.