{"id":26000,"library":"node-elm-compiler","title":"node-elm-compiler","description":"Node.js interface to compile Elm 0.19 sources using the official Elm compiler binaries. Current stable version 5.0.6. Provides a programmatic API for compiling Elm files to JavaScript or HTML, finding module dependencies, and reporting compile errors. Key differentiators: wraps the Elm binary, supports sync and async compilation, debug and optimize modes, and respects the elm.json configuration. Notably, requires Elm itself to be installed separately and handles version-specific flags for Elm 0.19.","status":"active","version":"5.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/rtfeldman/node-elm-compiler","tags":["javascript","elm","compiler","node"],"install":[{"cmd":"npm install node-elm-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add node-elm-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-elm-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"locates Elm dependencies in elm.json","package":"find-elm-dependencies","optional":false},{"reason":"utilities for options merging and array manipulation","package":"lodash","optional":false},{"reason":"creates temporary directories for compilation output","package":"temp","optional":false}],"imports":[{"note":"ESM since v5. Named export.","wrong":"const nodeElmCompiler = require('node-elm-compiler'); nodeElmCompiler.compile()","symbol":"compile","correct":"import { compile } from 'node-elm-compiler'"},{"note":"ESM named export. Returns compiled JavaScript as string.","wrong":"import nodeElmCompiler from 'node-elm-compiler'; nodeElmCompiler.compileToString()","symbol":"compileToString","correct":"import { compileToString } from 'node-elm-compiler'"},{"note":"ESM named export. Accepts array of module names.","wrong":"const findAllDependencies = require('node-elm-compiler').findAllDependencies","symbol":"findAllDependencies","correct":"import { findAllDependencies } from 'node-elm-compiler'"},{"note":"ESM named export. Synchronous version added in v4.3.0.","wrong":"import { compile } from 'node-elm-compiler'; compile.sync()","symbol":"compileSync","correct":"import { compileSync } from 'node-elm-compiler'"}],"quickstart":{"code":"import { compileToString } from 'node-elm-compiler';\nimport path from 'path';\n\nconst elmSource = path.resolve('src/Main.elm');\n\nasync function build() {\n  try {\n    const jsString = await compileToString([elmSource], {\n      optimize: false,\n      debug: false,\n      cwd: process.cwd(),\n      pathToMake: '' // uses system PATH\n    });\n    console.log('Compiled output length:', jsString.length);\n    // write to file etc.\n  } catch (err) {\n    console.error('Compilation failed:', err.message);\n  }\n}\n\nbuild();","lang":"typescript","description":"Demonstrates async compilation of an Elm source file to a JavaScript string using named import and options object."},"warnings":[{"fix":"Remove 'yes' from options and adapt error handling to use try/catch.","message":"v5.0.0 removed the 'yes' option and changed error handling to throw exceptions instead of emitting warnings or using process.exit.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Instead of using 'warn', rely on compiler output; for 'pathToMake', ensure elm binary is on PATH or use the correct path.","message":"The 'warn' and 'pathToMake' flags are obsolete and will result in helpful errors.","severity":"deprecated","affected_versions":">=5.0.1"},{"fix":"Install Elm e.g. via npm: 'npm install -g elm' or have elm on your PATH.","message":"Requires Elm compiler (elm binary) to be installed separately; this package only wraps it.","severity":"gotcha","affected_versions":"all"},{"fix":"Use import syntax or set \"type\": \"module\" in package.json. Consider using dynamic import() as fallback.","message":"ESM-only from v5.0.0; CommonJS require will fail with 'ERR_REQUIRE_ESM'.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install node-elm-compiler' and ensure your package.json includes it.","cause":"Package not installed or version incompatible","error":"Cannot find module 'node-elm-compiler'"},{"fix":"Switch to import syntax, or update to a legacy version (4.x) if you must use require.","cause":"Using require() with ESM-only version 5.x","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Verify the file path; use absolute paths or ensure relative paths are resolved correctly.","cause":"The provided path to the Elm source file is incorrect","error":"Error: Compilation failed: The file MyFile.elm does not exist."},{"fix":"Install Elm globally or specify correct 'pathToMake' option.","cause":"Elm binary not found or not installed","error":"Command failed: elm make ... No such file or directory"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}