node Errors

110 error patterns

node3 fixes

EADDRINUSE: Port already in use

Error: listen EADDRINUSE.*port

  • Kill process using the port: lsof -i :PORT
  • Use different port
node3 fixes

ECONNREFUSED: Connection refused

Error: connect ECONNREFUSED

  • Check target server is running
  • Verify host and port are correct
node3 fixes

ENOENT: No such file or directory

ENOENT.*no such file or directory

  • Check file path is correct
  • Use path.resolve for absolute paths
node3 fixes

EACCES: Permission denied

EACCES.*permission denied

  • Fix file permissions with chmod
  • Don't run as root; fix ownership
node3 fixes

ERR_MODULE_NOT_FOUND (ESM)

ERR_MODULE_NOT_FOUND

  • Add .js extension to import paths in ESM
  • Check package.json exports field
node3 fixes

ERR_REQUIRE_ESM: require() of ES Module

ERR_REQUIRE_ESM

  • Use dynamic import() instead of require()
  • Convert project to ESM (type:module)
node3 fixes

ERR_UNKNOWN_FILE_EXTENSION: .ts files

ERR_UNKNOWN_FILE_EXTENSION.*\.ts

  • Use ts-node/esm loader or tsx
  • Register TypeScript loader: --loader tsx
node3 fixes

JWT: Invalid token or signature

JsonWebTokenError.*invalid (token|signature)

  • Verify JWT secret matches between sign and verify
  • Check token hasn't been tampered with
node3 fixes

JWT: Token expired

TokenExpiredError.*jwt expired

  • Implement refresh token flow
  • Check server time synchronization
node3 fixes

JWT: Token not yet active (nbf)

NotBeforeError.*jwt not active

  • Check system clock synchronization
  • Wait until nbf time passes
node3 fixes

Express: 404 Cannot GET/POST route

(Express|app\.use).*404.*Cannot (GET|POST|PUT|DELETE)

  • Check route path matches request
  • Verify middleware/router order
node3 fixes

Cannot set headers after they are sent

Error.*headers.*already.*sent

  • Add return after res.send/json/redirect
  • Don't call res.send twice
node3 fixes

PayloadTooLargeError: Request entity too large

(body-parser|express\.json).*entity too large

  • Increase limit: express.json({ limit: '50mb' })
  • Use streaming for large files
node3 fixes

CORS: Origin not allowed

CORS.*Origin.*not allowed|No 'Access-Control-Allow-Origin'

  • Add cors middleware: app.use(cors())
  • Configure allowed origins
node3 fixes

CORS: Preflight OPTIONS request failing

CORS.*preflight.*405

  • Handle OPTIONS method in route
  • Add cors() middleware before routes
node3 fixes

Multer: Unexpected field name

Multer.*Unexpected field

  • Match field name in upload.single('fieldName') to form field
  • Check multipart form data field names
node3 fixes

Multer: File size exceeds limit

Multer.*File too large|LIMIT_FILE_SIZE

  • Increase limits: { fileSize: 10 * 1024 * 1024 }
  • Show user-friendly error message
node3 fixes

Multer: Too many files uploaded

Multer.*LIMIT_UNEXPECTED_FILE

  • Increase maxCount in upload.array()
  • Limit file count on client side
node3 fixes

Busboy: Missing content-type header

busboy.*missing content-type

  • Ensure request has multipart/form-data content-type
  • Check client sends correct headers
node3 fixes

WebSocket: Connection reset

(WebSocket|ws).*ECONNRESET|connection.*reset

  • Implement reconnection logic
  • Handle close event and retry
node3 fixes

WebSocket: Invalid frame header

(WebSocket|ws).*invalid frame header

  • Check for proxy stripping upgrade headers
  • Verify WebSocket protocol version
node3 fixes

Socket.IO CORS blocked

socket\.io.*CORS.*blocked

  • Configure cors in io options: { cors: { origin: '*' } }
  • Add specific origin to Socket.IO cors
node3 fixes

Socket.IO transport close/disconnect

socket\.io.*transport.*close|disconnect

  • Increase pingTimeout and pingInterval
  • Check client transport configuration
node3 fixes

Worker thread out of memory

(Worker|worker_threads).*ERR_WORKER_OUT_OF_MEMORY

  • Increase worker memory: resourceLimits.maxOldGenerationSizeMb
  • Process data in smaller chunks
node3 fixes

Worker: Cannot transfer MessagePort

(Worker|worker_threads).*Cannot.*transfer.*MessagePort

  • Pass MessagePort in transferList array
  • Don't use port after transferring
node3 fixes

child_process spawn ENOENT

child_process.*ENOENT.*spawn

  • Check command exists in PATH
  • Use full path to executable
node3 fixes

child_process: Operation not permitted

child_process.*EPERM|Operation not permitted

  • Check file has execute permissions
  • Run with appropriate user privileges
node3 fixes

Crypto: Unsupported algorithm (OpenSSL)

(crypto|ERR_OSSL).*unsupported.*algorithm

  • Use supported algorithm: sha256, aes-256-gcm
  • Check Node.js version supports algorithm
node3 fixes

Crypto: Invalid IV length

crypto.*ERR_CRYPTO_INVALID_IV_LENGTH

  • Use correct IV length for algorithm (16 bytes for AES)
  • Generate IV with crypto.randomBytes(16)
node3 fixes

Crypto: Invalid key length

crypto.*ERR_CRYPTO_INVALID_KEY_LENGTH

  • Use correct key length (32 bytes for AES-256)
  • Derive key with scrypt/pbkdf2 to correct length
node3 fixes

Buffer(): Deprecated Buffer constructor

(Buffer|DEP0005).*new Buffer.*deprecated

  • Use Buffer.from() for strings/arrays
  • Use Buffer.alloc() for new buffers
node3 fixes

ERR_INVALID_ARG_TYPE: Expected string

ERR_INVALID_ARG_TYPE.*"(path|buffer)".*must be.*string

  • Convert value to string before passing
  • Check argument types match API requirements
node3 fixes

Fetch/Undici: Connect timeout

(fetch|undici).*ConnectTimeoutError

  • Increase timeout: signal: AbortSignal.timeout(30000)
  • Check network connectivity
node3 fixes

Fetch/Undici: Body timeout

(fetch|undici).*BodyTimeoutError

  • Increase bodyTimeout in undici options
  • Stream large responses instead
node3 fixes

Fetch/Undici: Headers timeout

(fetch|undici).*HeadersTimeoutError

  • Increase headersTimeout option
  • Check server response time
node3 fixes

AbortError: Operation was aborted

AbortError.*aborted|ERR_ABORTED

  • Handle AbortError in catch block
  • Increase timeout duration
node3 fixes

AbortController: Signal already aborted

(AbortController|signal).*already.*aborted

  • Create new AbortController for each request
  • Don't reuse aborted controllers
node3 fixes

HTTP/2 stream cancelled

ERR_HTTP2_STREAM_CANCEL

  • Handle stream cancellation gracefully
  • Implement retry logic
node3 fixes

npm: No matching version found

ETARGET|No matching version found

  • Check package name spelling
  • Verify version exists: npm view package versions
node3 fixes

npm: Unable to resolve dependency tree

ERESOLVE.*unable to resolve.*dependency tree

  • Use --legacy-peer-deps flag
  • Fix peer dependency conflicts
node3 fixes

Rate limit exceeded (429)

rate.*limit.*exceeded|429.*Too Many Requests

  • Implement exponential backoff
  • Use rate limiting library (bottleneck, p-queue)
node3 fixes

Fastify: Invalid content length

(Fastify|fastify).*FST_ERR_CTP_INVALID_CONTENT_LENGTH

  • Set correct Content-Length header
  • Use transfer-encoding: chunked
node3 fixes

Fastify: Hook timeout

(Fastify|fastify).*FST_ERR_HOOK_TIMEOUT

  • Increase hook timeout in plugin options
  • Ensure hooks call done() or return promise
node3 fixes

Fastify: Already decorated with this name

(Fastify|fastify).*already.*decorated

  • Check for duplicate decorators
  • Use hasDecorator() before decorating
node3 fixes

Fastify: Schema validation failed

(Fastify|fastify).*schema.*validation.*failed

  • Fix request body to match JSON schema
  • Check required fields in schema
node3 fixes

Hono: Route not found 404

(Hono|hono).*Not Found.*404

  • Check route registration order
  • Verify HTTP method matches
node3 fixes

Hono: Middleware not calling next()

(Hono|hono).*middleware.*next.*not called

  • Call await next() in middleware
  • Return response or call next
node3 fixes

EPIPE: Broken pipe

EPIPE.*Broken pipe

  • Handle EPIPE error in stream error handler
  • Client disconnected before response sent
node3 fixes

ERR_HTTP_HEADERS_SENT

ERR_HTTP_HEADERS_SENT|Cannot.*headers.*already sent

  • Return after sending response
  • Don't send multiple responses
node3 fixes

ERR_STREAM_WRITE_AFTER_END

ERR_STREAM_WRITE_AFTER_END

  • Check stream.writable before writing
  • Handle end event properly
node3 fixes

ERR_STREAM_PREMATURE_CLOSE

ERR_STREAM_PREMATURE_CLOSE

  • Handle stream close/error events
  • Use pipeline() for proper error propagation
node3 fixes

ERR_SOCKET_BAD_PORT: Port out of range

ERR_SOCKET_BAD_PORT|port.*should be.*0.*65535

  • Use port number between 0 and 65535
  • Parse port to integer: parseInt(process.env.PORT)
node3 fixes

TLS: Certificate hostname mismatch

ERR_TLS_CERT_ALTNAME_INVALID

  • Ensure certificate covers the hostname
  • Use correct hostname matching SAN
node3 fixes

TLS: Self-signed certificate error

UNABLE_TO_VERIFY_LEAF_SIGNATURE|SELF_SIGNED_CERT

  • Add CA certificate to trusted: ca option
  • Set NODE_TLS_REJECT_UNAUTHORIZED=0 for dev
node3 fixes

TLS: Certificate authority invalid

ERR_CERT_AUTHORITY_INVALID

  • Install proper root CA certificate
  • Set NODE_EXTRA_CA_CERTS environment variable
node3 fixes

ETIMEDOUT: Connection timed out

ETIMEDOUT|connect ETIMEDOUT

  • Increase connection timeout
  • Check network connectivity and DNS
node3 fixes

ENOTFOUND: DNS lookup failed

ENOTFOUND|getaddrinfo.*ENOTFOUND

  • Check hostname spelling
  • Verify DNS resolution works
node3 fixes

EMFILE: Too many open files

EMFILE.*too many open files

  • Increase file descriptor limit: ulimit -n
  • Use graceful-fs package
node3 fixes

ERR_ASYNC_CALLBACK: Callback not a function

ERR_ASYNC_CALLBACK.*callback.*not.*function

  • Pass function as callback argument
  • Check callback parameter isn't undefined
node3 fixes

Prisma P2002: Unique constraint violation

Prisma.*P2002.*Unique constraint failed

  • Handle duplicate with upsert or try/catch
  • Check unique fields before creating
node3 fixes

Prisma P2025: Record not found

Prisma.*P2025.*Record.*not found

  • Use findUnique with null check instead of findUniqueOrThrow
  • Validate ID exists before update/delete
node3 fixes

Prisma P2003: Foreign key constraint

Prisma.*P2003.*Foreign key constraint failed

  • Ensure referenced record exists
  • Check cascade delete settings
node3 fixes

Prisma P1001: Cannot reach database

Prisma.*P1001.*Can't reach database server

  • Check DATABASE_URL connection string
  • Verify database server is running
node3 fixes

Drizzle ORM: Column does not exist

Drizzle.*column.*does not exist

  • Run migrations: drizzle-kit push
  • Check schema matches database
node3 fixes

Native crypto module build failed

(bcrypt|argon2).*ERR_DLOPEN_FAILED|native module

  • Rebuild native modules: npm rebuild
  • Install build tools (node-gyp prerequisites)
node3 fixes

CSP: Resource blocked by Content-Security-Policy

(helmet|csp).*Content Security Policy.*blocked

  • Add source to correct CSP directive
  • Use nonce for inline scripts
node3 fixes

Express session store disconnected

session.*store.*disconnect|connect\.session

  • Check Redis/database connection for session store
  • Handle store disconnect event
node3 fixes

Passport: Failed to serialize user

(passport|authenticate).*Failed to serialize user

  • Implement serializeUser: pass user.id to done()
  • Check user object has id property
node3 fixes

Passport: No strategy registered

(passport|authenticate).*No strategy.*registered

  • Call passport.use(new Strategy()) before authenticate
  • Check strategy name matches
node3 fixes

HTTP/2 session destroyed/invalid

ERR_HTTP2_INVALID_SESSION|Session.*destroyed

  • Create new session after close
  • Handle session close event
node3 fixes

Zod validation: Type mismatch

(zod|ZodError).*invalid_type.*Expected.*received

  • Fix input data type to match schema
  • Add coercion: z.coerce.number()
node3 fixes

JavaScript heap out of memory

(ENOMEM|JavaScript heap out of memory)

  • Increase memory: --max-old-space-size=4096
  • Process data in streams/chunks
node3 fixes

ERR_USE_AFTER_CLOSE: Resource used after close

ERR_USE_AFTER_CLOSE|use.*after.*close

  • Check resource state before operations
  • Don't reference connection after closing
node3 fixes

ERR_UNESCAPED_CHARACTERS in URL

ERR_UNESCAPED_CHARACTERS.*in request path

  • Use encodeURIComponent for URL parameters
  • Sanitize URL path before request
node3 fixes

Invalid cron expression

(cron|node-cron|agenda).*Invalid.*expression

  • Verify cron syntax (5 or 6 fields)
  • Use cron expression validator
node3 fixes

Redis: Connection refused

(Redis|IORedis|redis).*ECONNREFUSED.*6379

  • Ensure Redis server is running
  • Check host/port configuration
node3 fixes

Redis: Authentication required

(Redis|IORedis).*NOAUTH.*Authentication required

  • Add password to Redis connection config
  • Set AUTH in Redis URL: redis://:password@host
node3 fixes

MongoDB: Connection refused

(mongoose|MongoDB).*ECONNREFUSED.*27017

  • Ensure MongoDB is running
  • Check connection string URI
node3 fixes

Mongoose: Operation buffering timed out

(mongoose|MongoDB).*buffering timed out

  • Ensure mongoose.connect() resolves before operations
  • Check connection state
node3 fixes

MongoDB: E11000 Duplicate key error

(mongoose|MongoDB).*E11000.*duplicate key

  • Handle duplicate with try/catch
  • Check unique index fields
node3 fixes

ERR_INVALID_URL: Invalid URL

ERR_INVALID_URL|Invalid URL

  • Validate URL format before parsing
  • Use new URL() with try/catch
node3 fixes

ERR_AMBIGUOUS_ARGUMENT in assert

ERR_AMBIGUOUS_ARGUMENT.*must not be.*falsy

  • Pass truthy message to assert
  • Don't pass empty string as message
node3 fixes

DeprecationWarning: punycode module

DeprecationWarning.*punycode.*module

  • Install userland punycode package
  • Update packages using deprecated module
node3 fixes

ExperimentalWarning: Fetch API

ExperimentalWarning.*Fetch API

  • Update Node.js to 21+ where fetch is stable
  • Add --no-warnings flag
node3 fixes

Logger: Stream not writable

(pino|winston|bunyan).*stream.*not writable

  • Check log file permissions
  • Ensure log directory exists
node3 fixes

Unhandled Promise Rejection

ERR_UNHANDLED_REJECTION.*No rejection handler

  • Add .catch() to all promises
  • Use process.on('unhandledRejection') handler
node3 fixes

BullMQ: Missing lock for job

(bull|bullmq).*Missing.*lock.*job

  • Increase lockDuration in worker options
  • Don't process job longer than lock duration
node3 fixes

BullMQ: Redis key type conflict

(bull|bullmq).*WRONGTYPE.*Operation against.*key.*different type

  • Clear the queue: remove old keys
  • Use different queue name
node3 fixes

ERR_INSPECTOR_NOT_AVAILABLE

ERR_INSPECTOR_NOT_AVAILABLE

  • Start Node.js with --inspect flag
  • Don't use inspector in production
node3 fixes

AWS SDK: No credentials found

(aws-sdk|@aws-sdk).*CredentialsError|No credentials

  • Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  • Configure ~/.aws/credentials
node3 fixes

AWS SDK: Network/Timeout error

(aws-sdk|@aws-sdk).*NetworkingError|TimeoutError

  • Check VPC/security group allows outbound
  • Increase maxRetries and timeout
node3 fixes

Sharp: libvips/installation error

sharp.*libvips|Cannot find module 'sharp'

  • Rebuild: npm rebuild sharp
  • Install platform-specific binary: npm install --platform=linux
node3 fixes

node-gyp: Build failed

node-gyp.*rebuild.*failed

  • Install build tools: build-essential, python3
  • On Windows: npm install -g windows-build-tools
node3 fixes

ESBuild: Could not resolve module

(ESBuild|esbuild).*Could not resolve

  • Add external for Node.js builtins
  • Configure resolve extensions
node3 fixes

Vite: Failed to resolve import

(Vite|vite).*Failed to resolve.*import

  • Check import path and file exists
  • Add to optimizeDeps.include
node3 fixes

Vite: Pre-transform error

(Vite|vite).*Pre-transform error

  • Clear Vite cache: rm -rf node_modules/.vite
  • Check for circular imports
node3 fixes

ERR_PACKAGE_PATH_NOT_EXPORTED

ERR_PACKAGE_PATH_NOT_EXPORTED

  • Check package.json exports field of dependency
  • Import from documented entry point
node3 fixes

ERR_PACKAGE_IMPORT_NOT_DEFINED

ERR_PACKAGE_IMPORT_NOT_DEFINED

  • Add imports field to package.json
  • Check subpath import mapping
node3 fixes

tsx/ts-node: Unknown file extension .ts

(tsx|ts-node).*ERR_UNKNOWN_FILE_EXTENSION

  • Use tsx instead of ts-node for ESM
  • Add --loader tsx to node command
node3 fixes

Test runner: import in non-module

(vitest|jest).*Cannot.*use.*import.*outside.*module

  • Add transform config for test runner
  • Set type:module or configure babel/swc
node4 fixes

Cannot use import/export outside a module

SyntaxError:.*Unexpected.*'export'|Cannot use import statement outside a module

  • Add `"type": "module"` to package.json for ESM
  • Rename file to .mjs for ESM or .cjs for CommonJS
node4 fixes

Module not found

ERR_MODULE_NOT_FOUND|Cannot find (module|package)

  • Run `npm install` to install missing dependencies
  • Check the import path for typos and correct casing
node4 fixes

Cannot require() an ES Module

ERR_REQUIRE_ESM|require\(\) of ES Module.*not supported

  • Use dynamic `import()` instead of `require()`
  • Downgrade to an older version of the package that supports CJS
node4 fixes

ENOENT: File or directory not found

ENOENT:.*no such file or directory

  • Check the file path for typos and ensure it exists
  • Use path.resolve() or path.join() for cross-platform paths
node4 fixes

EACCES: Permission denied

EACCES:.*permission denied

  • Fix folder permissions: `chmod -R 755 <directory>` or take ownership on Windows
  • Avoid running npm with sudo — fix npm prefix: `npm config set prefix ~/.npm-global`
node4 fixes

EPERM: Operation not permitted

EPERM:.*operation not permitted

  • Close applications that may have the file open (editors, dev servers)
  • Run terminal as Administrator (Windows) or with sudo (Unix)
node3 fixes

EADDRINUSE: Port already in use

EADDRINUSE:.*address already in use.*:\d+

  • Kill the process using the port: `npx kill-port <port>` or `lsof -ti:<port> | xargs kill`
  • Use a different port via environment variable or CLI flag
node3 fixes

ENOSPC: Too many file watchers or no disk space

Error:.*ENOSPC|no space left on device|System limit for number of file watchers reached

  • Increase file watcher limit: `echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`
  • Free disk space — clear node_modules caches: `npm cache clean --force`
node4 fixes

ENAMETOOLONG: File path too long

Error:.*ENAMETOOLONG|file name too long

  • Shorten the file path or move the project closer to the root directory
  • On Windows, enable long paths: `git config --system core.longpaths true`
node4 fixes

JavaScript heap out of memory

heap out of memory|FATAL ERROR:.*allocation failed|JavaScript heap out of memory

  • Increase Node.js memory: `node --max-old-space-size=8192`
  • Set via env: `NODE_OPTIONS=--max-old-space-size=8192`