{"id":18223,"library":"cmake-js","title":"CMake.js","description":"CMake.js is a Node.js native addon build tool that replaces node-gyp's gyp with CMake. Current stable version is 8.0.0 (released late 2024), requiring Node.js >=20.17.0 or >=22.9.0. It supports Node.js, NW.js, and Electron runtimes out of the box, with automatic runtime detection and build configuration. Key differentiators: uses CMake instead of GYP, supports modern Node.js versions, built-in fetch for smaller install size, and native addon development without post-build steps for Electron/NW.js. Release cadence is irregular with major version bumps roughly every 1-2 years, each introducing breaking changes.","status":"active","version":"8.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/cmake-js/cmake-js","tags":["javascript","native","addon","module","c","c++","bindings","build","buildtools"],"install":[{"cmd":"npm install cmake-js","lang":"bash","label":"npm"},{"cmd":"yarn add cmake-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add cmake-js","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required build tool - CMake.js requires CMake to be installed on the system","package":"cmake","optional":false}],"imports":[{"note":"cmake-js is primarily used as a CLI tool, not a library import. Use npx or install globally.","wrong":"node -e \"require('cmake-js')\"","symbol":"default (cmake-js CLI)","correct":"npx cmake-js build"},{"note":"cmake-js is CommonJS-only. ESM import is not supported.","wrong":"import cmakejs from 'cmake-js';","symbol":"CMakeJS (programmatic API)","correct":"const cmakejs = require('cmake-js');"}],"quickstart":{"code":"// Create a minimal CMakeLists.txt in your project root:\n// cmake_minimum_required(VERSION 3.10)\n// project(MyNativeAddon)\n// include(../node_modules/cmake-js/cmake-js.cmake)\n\n// Then build:\n// npx cmake-js compile\n\n// Example package.json build script:\n// { \"scripts\": { \"build\": \"cmake-js compile\" } }","lang":"javascript","description":"Shows minimal setup: CMakeLists.txt with cmake-js include hook, and CLI compile command."},"warnings":[{"fix":"Upgrade Node.js to ^20.17.0 || >=22.9.0","message":"v8.0.0 dropped support for Node.js <20.17.0 and <22.9.0","severity":"breaking","affected_versions":"<8.0.0"},{"fix":"Use v6.x for older Node.js or upgrade Node.js to 14.15+","message":"v7.0.0 removed support for Node.js <14.15","severity":"breaking","affected_versions":">=7.0.0 <8.0.0"},{"fix":"Update CMakeLists.txt to use new variable names as per upgrade guide","message":"v7.0.0 changed CMake variable naming conventions - CMAKE_JS_SRC etc. require updates to CMakeLists.txt","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use Visual Studio 2015 or newer","message":"v4.0.0 removed support for Visual Studio 2013 and older","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use --cmake-path or -DCMAKE_TOOLCHAIN_FILE=... when targeting different architecture","message":"Cross-compilation requires manual CMAKE_TOOLCHAIN_FILE specification","severity":"gotcha","affected_versions":"*"},{"fix":"Use: cmake-js compile --runtime=electron --runtimeVersion=28.0.0","message":"Electron builds require --runtime=electron --runtime-version=X.Y.Z flags to match Electron's Node.js ABI","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add 'include(../node_modules/cmake-js/cmake-js.cmake)' to CMakeLists.txt, or run 'npm install cmake-js'","cause":"CMakeLists.txt missing include line or cmake-js not installed","error":"CMake Error: Could not find cmake module file: cmake-js.cmake"},{"fix":"Specify runtime explicitly: --runtime=node --runtime-version=20.0.0","cause":"cmake-js cannot auto-detect runtime from Node.js version","error":"Error: Unable to detect runtime. Use --runtime and --runtime-version."},{"fix":"Install CMake >=3.10 and ensure generator matches platform (e.g., 'Unix Makefiles' on Linux, 'Visual Studio 17 2022' on Windows)","cause":"Missing CMake installation or incompatible generator","error":"npm ERR! command cmake-js compile failed (exit code 1)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}