Skip to content

Node 24 compatibility: __dirname not defined in ES module scope #17

@cmgmyr

Description

@cmgmyr

Description

The plugin hooks fail on Node.js v24 because the compiled JS uses __dirname, which is not available in ES modules. Since package.json has "type": "module", Node 24 treats .js files as ESM and __dirname is undefined.

This causes the smart installer (smart-install.js) to crash silently on session start, so dependencies never get installed. The stop.js hook then fails with MODULE_NOT_FOUND because node_modules is missing.

Error

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension
and package.json contains "type": "module".
    at file:///.../.claude/plugins/marketplaces/memvid/dist/hooks/smart-install.js:18:68

Steps to Reproduce

  1. Install Node.js v24
  2. Install the plugin via Claude Code
  3. Start a new Claude Code session
  4. The session-start hook crashes, deps are never installed
  5. The stop hook fails with Cannot find module 'proper-lockfile'

Suggested Fix

Replace __dirname with the ESM equivalent:

import { fileURLToPath } from "url";
import { dirname } from "path";

const __dirname = dirname(fileURLToPath(import.meta.url));

Or use import.meta.dirname (available in Node 21+).

Environment

  • Node.js: v24.14.0
  • Plugin version: 1.0.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions