Skip to content

fix: replace code-preview.vue with TypeScript render function to fix SSR ERR_UNKNOWN_FILE_EXTENSION#44

Open
NullVoxPopuli-ai-agent wants to merge 1 commit into
aklkv:mainfrom
NullVoxPopuli-ai-agent:fix/vue-ssr-unknown-extension
Open

fix: replace code-preview.vue with TypeScript render function to fix SSR ERR_UNKNOWN_FILE_EXTENSION#44
NullVoxPopuli-ai-agent wants to merge 1 commit into
aklkv:mainfrom
NullVoxPopuli-ai-agent:fix/vue-ssr-unknown-extension

Conversation

@NullVoxPopuli-ai-agent
Copy link
Copy Markdown

Problem

Fixes #39

When a project uses vite-plugin-ember and runs vitepress build, it fails with:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".vue" for .../vite-plugin-ember/src/vitepress/code-preview.vue

Root cause: dist/vitepress/setup.js contains a dynamic import pointing back to the raw .vue source:

// dist/vitepress/setup.js (compiled from setup.ts line 79)
const CodePreview = defineAsyncComponent(
  () => import('../../src/vitepress/code-preview.vue'),
);

During VitePress's SSR build, vite-plugin-ember is loaded from node_modules and treated as external — its dynamic imports are resolved by Node.js native ESM, not Vite's transform pipeline. Node.js ESM does not recognise .vue as a valid module extension, so it throws ERR_UNKNOWN_FILE_EXTENSION.

Fix

Convert code-preview.vue to code-preview.ts using Vue's defineComponent + render-function API:

  • tsc compiles it to dist/vitepress/code-preview.js — a plain JS file that Node.js ESM can load natively.
  • setup.ts now imports ./code-preview.js (the compiled output) instead of ../../src/vitepress/code-preview.vue.
  • Scoped CSS is replaced with a lightweight runtime style-injection that runs once on first client mount (guarded by document check, so SSR-safe).
  • The ./components/CodePreview package export is updated to point to the compiled dist/vitepress/code-preview.js.

Test plan

  • cd vite-plugin-ember && pnpm build compiles without errors
  • dist/vitepress/code-preview.js exists and imports only .js/built modules
  • dist/vitepress/setup.js imports ./code-preview.js, not a .vue file
  • VitePress docs build (cd docs && pnpm build) completes without the extension error
  • Live demo components still render correctly in the browser

🤖 Generated with Claude Code

…d SSR extension error

Node.js ESM cannot load .vue files natively. When vite-plugin-ember is in
node_modules and VitePress runs its SSR build, the dynamic import of
../../src/vitepress/code-preview.vue in dist/vitepress/setup.js is resolved
by Node.js directly, causing ERR_UNKNOWN_FILE_EXTENSION.

Convert code-preview.vue to code-preview.ts using Vue's render function API
so tsc compiles it to a plain .js file that Node.js ESM can load without
Vite's transform pipeline. CSS is injected once into the document head on
first mount instead of relying on SFC scoped styles.

Fixes aklkv#39

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-fireplace that referenced this pull request Apr 20, 2026
… build

Applies the fix from aklkv/vite-plugin-ember#44 as a pnpm patch.

The published dist/vitepress/setup.js dynamically imports
code-preview.vue from source, which Node ESM cannot load during
VitePress SSR. The patch replaces that import with a compiled
.js render-function equivalent.

Ref: aklkv/vite-plugin-ember#44
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-fireplace that referenced this pull request Apr 20, 2026
… SSR build

The published dist/vitepress/setup.js dynamically imports
code-preview.vue from source, which Node ESM cannot load during
VitePress SSR. This pnpm patch backports the fix from
aklkv/vite-plugin-ember#44 so the docs build works today without
waiting for a new release.

Ref: aklkv/vite-plugin-ember#44
NullVoxPopuli-ai-agent pushed a commit to NullVoxPopuli-ai-agent/ember-fireplace that referenced this pull request Apr 20, 2026
… SSR build

The published dist/vitepress/setup.js dynamically imports
code-preview.vue from source, which Node ESM cannot load during
VitePress SSR. This pnpm patch backports the fix from
aklkv/vite-plugin-ember#44 so the docs build works today without
waiting for a new release.

Ref: aklkv/vite-plugin-ember#44
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.

Unknown file extension ".vue" when building

2 participants