Skip to content

ESM module resolution fails: Cannot find module './tools/index' #2

@Nik-Kras

Description

@Nik-Kras

I tried to connect the MCP to Claude Code and it failed with ERR_MODULE_NOT_FOUND

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/to/node_modules/@cmd8/excalidraw-mcp/dist/tools/index' imported from /path/to/node_modules/@cmd8/excalidraw-mcp/dist/index.js

Probably the bug happened because of a mismatch between development tooling and Node.js runtime requirements

// This works in bundlers, fails in Node.js ESM:                                         
import { foo } from './utils/helper'                                                     
                                                                                       
// Node.js ESM requires:                                                                 
import { foo } from './utils/helper.js'

Root Cause

The package has an ESM configuration mismatch:

  1. package.json has "type": "module" (ESM mode)
  2. tsconfig.json uses "moduleResolution": "bundler" which allows extensionless
    imports
  3. tsc compiles the TypeScript without adding .js extensions
  4. Node.js ESM requires explicit .js extensions for relative imports

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions