If you've ever copied a working AI automation script, run node tool.js, and watched it die with Cannot use import statement outside a module or fetch is not defined — this article gets you unstuck. By the end you'll have a 30-second decision tree to tell whether the bug lives in your package.json, your tsconfig.json, or your runtime, plus two copy-paste diagnostic scripts that print exactly which environment you're in and why your imports resolved the way they did.

These five failures account for the majority of "the code is identical but it won't run on my machine" reports I see in AI-tooling repos. None of them are logic bugs. They're all configuration mismatches between how your code is written and how the JavaScript engine is told to read it.

Failure 1: Cannot use import statement — the package.json type field vs Claude SDK examples

The single most common breakage. You grab a snippet from the Anthropic SDK README:

import Anthropic from '@anthropic-ai/sdk';