Skip to content

'[Bug] 'Dynamic require of "fs" is not supported' #5

Description

@davidhawdale

Describe the bug

I get a screen telling me that 'Dynamic require of "fs" is not supported'

To Reproduce

Open http://localhost:5173/

Claude tells me this is the fix (I am not a developer!)

1. require('fs') in ESM Vite config + missing gap-analysis.md middleware

File: tools/dashboard/vite.config.ts

Two issues:

  1. The custom dev server middleware used require('fs') inside an ESM module, which is not allowed — this caused a 500 error whenever the browser requested hypotheses.md.
  2. There was no middleware for gap-analysis.md, so it was never served.

Before:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

const projectRoot = path.resolve(__dirname, '..', '..')

export default defineConfig({
  plugins: [
    react(),
    {
      name: 'serve-strategy',
      configureServer(server) {
        server.middlewares.use('/hypotheses.md', (_req, res) => {
          const fs = require('fs')   // ❌ require() not allowed in ESM
          const filePath = path.join(projectRoot, 'strategy', 'hypotheses.md')
          try {
            const content = fs.readFileSync(filePath, 'utf-8')
            res.setHeader('Content-Type', 'text/markdown')
            res.end(content)
          } catch {
            res.statusCode = 404
            res.end('Not found')
          }
        })
      },
    },
    // ❌ no middleware for gap-analysis.md
  ],
})

After:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import fs from 'fs'  // ✅ ESM import at top of file

const projectRoot = path.resolve(__dirname, '..', '..')

function serveStrategyFile(urlPath: string, filePath: string) {
  return {
    name: `serve-strategy-${urlPath.replace(/\W/g, '-')}`,
    configureServer(server: import('vite').ViteDevServer) {
      server.middlewares.use(urlPath, (_req, res) => {
        try {
          const content = fs.readFileSync(filePath, 'utf-8')
          res.setHeader('Content-Type', 'text/markdown')
          res.end(content)
        } catch {
          res.statusCode = 404
          res.end('Not found')
        }
      })
    },
  }
}

export default defineConfig({
  plugins: [
    react(),
    serveStrategyFile('/hypotheses.md', path.join(projectRoot, 'strategy', 'hypotheses.md')),
    serveStrategyFile('/gap-analysis.md', path.join(projectRoot, 'strategy', 'gap-analysis.md')), // ✅ added
  ],
})

Expected behavior

a visual dashboard

Environment

  • OS: [Mac Tahoe
  • Claude Code version: Sonnet
  • LeanOS version: Core

Additional context

Image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions