{"id":43277,"library":"mysql-error-codes","title":"mysql-error-codes","description":"Provides a comprehensive, typed mapping of MySQL server error codes to their symbolic names (e.g., ER_DUP_ENTRY) for Node.js and TypeScript projects. Current version 0.1.3 is stable but rarely updated; includes all standard MySQL error codes up to MySQL 8.0. Ships with TypeScript definitions, supports both ESM and CommonJS imports, and is dependency-free. Useful for handling MySQL errors without magic numbers.","status":"active","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/sambrmg/mysql-error-codes","tags":["javascript","mysql","mysql-error-codes","node","ts","typescript","codes"],"install":[{"cmd":"npm install mysql-error-codes","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-error-codes","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-error-codes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM: must use named import because the export is not a default export.","wrong":"import MysqlErrorCodes from 'mysql-error-codes'","symbol":"MysqlErrorCodes","correct":"import { MysqlErrorCodes } from 'mysql-error-codes'"},{"note":"CommonJS: destructure the required object because the module exports an object with MysqlErrorCodes as a property.","wrong":"const MysqlErrorCodes = require('mysql-error-codes')","symbol":"MysqlErrorCodes","correct":"const { MysqlErrorCodes } = require('mysql-error-codes')"},{"note":"Error codes are accessed as properties of the MysqlErrorCodes object, not as top-level exports.","wrong":"ER_DUP_ENTRY","symbol":"ER_DUP_ENTRY","correct":"MysqlErrorCodes.ER_DUP_ENTRY"}],"quickstart":{"code":"import { MysqlErrorCodes } from 'mysql-error-codes';\n\n// Example: check for duplicate entry error (MySQL error 1062)\nconst mysql = require('mysql2/promise');\nconst connection = await mysql.createConnection({\n  host: 'localhost',\n  user: 'root',\n  password: process.env.DB_PASSWORD ?? '',\n  database: 'test'\n});\n\ntry {\n  await connection.execute(\"INSERT INTO users (id) VALUES (1)\");\n} catch (err) {\n  if (err.code === MysqlErrorCodes.ER_DUP_ENTRY) {\n    console.log('Duplicate entry!');\n  } else {\n    console.log('Other error:', err.message);\n  }\n}\n\nawait connection.end();","lang":"typescript","description":"Shows how to import and use MysqlErrorCodes to check for duplicate entry error (ER_DUP_ENTRY) after an INSERT failure."},"warnings":[{"fix":"Use destructured require or named import: const { MysqlErrorCodes } = require('mysql-error-codes');","message":"The package exports an object with a single property 'MysqlErrorCodes'. CommonJS users must destructure: const { MysqlErrorCodes } = require('mysql-error-codes').","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check the MySQL error reference for any missing codes and contribute to the package, or use an alternative like 'mysql-error-codes' from another source.","message":"The package does not include newer MySQL 8.x error codes added after its last release. Error codes may be missing or outdated.","severity":"gotcha","affected_versions":">=0.1.3"},{"fix":"Always import from 'mysql-error-codes' without specifying a file extension.","message":"Importing the module with an incorrect path (e.g., 'mysql-error-codes/index') may cause resolution issues in bundlers.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.1.3':30 '8.0':45 'code':4,14,41,74,78 'commonj':54 'comprehens':7 'current':28 'definit':49 'depend':59 'dependency-fre':58 'dup':21 'e.g':19 'entri':22 'er':20 'error':3,13,40,65,73 'esm':52 'free':60 'handl':63 'import':55 'includ':36 'javascript':69 'magic':67 'map':9 'mysql':2,11,39,44,64,70,72 'mysql-error-cod':1,71 'name':18 'node':75 'node.js':24 'number':68 'project':27 'provid':5 'rare':34 'server':12 'ship':46 'stabl':32 'standard':38 'support':50 'symbol':17 'ts':76 'type':8 'typescript':26,48,77 'updat':35 'use':61 'version':29 'without':66","created_at":"2026-06-05T16:59:02.065724+00:00","updated_at":"2026-06-05T16:59:02.065724+00:00","problems":[{"fix":"Ensure you use const { MysqlErrorCodes } = require('mysql-error-codes'); (with parentheses).","cause":"CommonJS code tried to destructure from require without wrapping in parentheses or using the wrong export.","error":"TypeError: Cannot destructure property 'MysqlErrorCodes' of 'require(...)' as it is undefined."},{"fix":"Run npm install --save mysql-error-codes and verify the package is in node_modules.","cause":"Package not installed or import path is incorrect.","error":"Module not found: Can't resolve 'mysql-error-codes'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sambrmg/mysql-error-codes#readme","github":"https://github.com/sambrmg/mysql-error-codes","docs":null,"changelog":null,"pypi":null,"npm":"mysql-error-codes","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}