Skip to content

Cannot use import statement outside a module #7

@StrandedKitty

Description

@StrandedKitty

I encountered this error after finishing a task in Claude Code.
Node v19.9.0 (npm v9.6.3)

⏺ Stop [/Users/***/.claude/count_tokens.js] failed with non-blocking status code 1: (node:35410) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs 
  extension.
  (Use `node --trace-warnings ...` to show where the warning was created)
  /Users/***/.claude/count_tokens.js:3
  import { readFile, stat, readdir, writeFile, mkdir } from 'node:fs/promises';
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
      at internalCompileFunction (node:internal/vm:73:18)
      at wrapSafe (node:internal/modules/cjs/loader:1195:20)
      at Module._compile (node:internal/modules/cjs/loader:1239:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
      at Module.load (node:internal/modules/cjs/loader:1133:32)
      at Module._load (node:internal/modules/cjs/loader:972:12)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
      at node:internal/main/run_main_module:23:47

  Node.js v19.9.0

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