{"id":41997,"library":"sql-minifier","title":"sql-minifier","description":"A lightweight npm package for minifying SQL statements by removing unnecessary whitespace and comments. Version 1.0.0, released recently, with no known release cadence. Handles single-line and multi-line comments, optionally preserves comments in condensed form, and detects unclosed strings/comments throwing errors. Performs minification in a single pass for efficiency. Minimal API surface with one main function.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/aeonzy/sql-minifier","tags":["javascript","sql","minifier","minify","database","query","compress","minify sql","sql minifier"],"install":[{"cmd":"npm install sql-minifier","lang":"bash","label":"npm"},{"cmd":"yarn add sql-minifier","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-minifier","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package uses CommonJS; ESM import may fail in Node unless using ES module resolution (e.g., .mjs file).","wrong":"import { minifySQL } from 'sql-minifier';","symbol":"minifySQL","correct":"const { minifySQL } = require('sql-minifier');"},{"note":"Do not assign require directly to minifySQL; it is a named export, not the default.","wrong":"const minifySQL = require('sql-minifier');","symbol":"default import","correct":"const sqlMinifier = require('sql-minifier');\nconst minified = sqlMinifier.minifySQL(sql);"},{"note":"Options must be passed as an object, not a bare boolean.","wrong":"const minified = minifySQL(sql, true);","symbol":"minifySQL with options","correct":"const { minifySQL } = require('sql-minifier');\nconst minified = minifySQL(sql, { includeComments: true });"}],"quickstart":{"code":"const { minifySQL } = require('sql-minifier');\nconst originalSQL = `SELECT * FROM users WHERE id = 1; -- comment`;\nconst minifiedWithoutComments = minifySQL(originalSQL);\nconsole.log(minifiedWithoutComments);\n// Output: 'SELECT * FROM users WHERE id=1;'\nconst minifiedWithComments = minifySQL(originalSQL, { includeComments: true });\nconsole.log(minifiedWithComments);\n// Output: 'SELECT * FROM users WHERE id=1; /*comment*/'","lang":"javascript","description":"Installs sql-minifier, minifies a SQL string with and without preserving comments, showing both outputs."},"warnings":[{"fix":"Use `const { minifySQL } = require('sql-minifier')` or configure your project to use CommonJS.","message":"The package does not support ES module imports (ESM). Using `import { minifySQL } from 'sql-minifier'` will fail unless the importing project uses CommonJS or Node's experimental ESM interop.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Always pass options as an object: `minifySQL(sql, { includeComments: true })`.","message":"Options must be passed as an object (e.g., `{ includeComments: true }`), not a boolean directly. Passing a boolean will be interpreted as a string with length.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Ensure your SQL does not depend on whitespace for parsing; write standard SQL that is whitespace-agnostic.","message":"The minifier removes newlines and multiple spaces, which may break SQL syntax that relies on whitespace (e.g., BETWEEN, IN lists). Not a bug, but a design choice.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Ensure string literals are properly escaped; avoid containing comment tokens inside strings that could confuse the minifier.","message":"Comments inside string literals will be preserved but may be misinterpreted if the minifier encounters unescaped quotes. The minifier does not fully parse SQL strings; it only detects string delimiters.","severity":"gotcha","affected_versions":"1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':19 'api':57 'cadenc':26 'comment':17,35,38 'compress':69 'condens':40 'databas':67 'detect':43 'effici':55 'error':47 'form':41 'function':62 'handl':27 'javascript':63 'known':24 'lightweight':5 'line':30,34 'main':61 'minif':49 'minifi':3,9,65,66,70,73 'minim':56 'multi':33 'multi-lin':32 'npm':6 'one':60 'option':36 'packag':7 'pass':53 'perform':48 'preserv':37 'queri':68 'recent':21 'releas':20,25 'remov':13 'singl':29,52 'single-lin':28 'sql':2,10,64,71,72 'sql-minifi':1 'statement':11 'strings/comments':45 'surfac':58 'throw':46 'unclos':44 'unnecessari':14 'version':18 'whitespac':15","created_at":"2026-06-04T18:55:07.293979+00:00","updated_at":"2026-06-04T18:55:07.293979+00:00","problems":[{"fix":"Use destructuring: `const { minifySQL } = require('sql-minifier')`.","cause":"Incorrect import: using default import with `const minifySQL = require('sql-minifier')` when minifySQL is a named export.","error":"TypeError: (0 , require(...).minifySQL) is not a function"},{"fix":"Use require or rename file to .mjs and ensure package.json has type:module.","cause":"Trying to use ES module import syntax in a CommonJS file without type:module.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Use `const { minifySQL } = require('sql-minifier')`.","cause":"Using `const minifySQL = require('sql-minifier').minifySQL` incorrectly or misspelling.","error":"minifySQL is not defined"}],"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/aeonzy/sql-minifier","github":"https://github.com/aeonzy/sql-minifier","docs":null,"changelog":null,"pypi":null,"npm":"sql-minifier","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-04","next_check":"2026-09-02","install_tag":null}}