{"id":19366,"library":"babel-template","title":"babel-template","description":"Generate an AST from a string template (quasiquote implementation). Current stable version is 6.26.0 (legacy Babel 6). Release cadence: infrequent; part of Babel monorepo, which has moved on to v7/v8. Key differentiator: allows building AST nodes using template syntax instead of manual node construction, but only works with Babel 6 AST types. For Babel 7+, use @babel/template instead.","status":"deprecated","version":"6.26.0","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-template","tags":["javascript"],"install":[{"cmd":"npm install babel-template","lang":"bash","label":"npm"},{"cmd":"yarn add babel-template","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-template","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required for AST node type references in template replacements","package":"babel-types","optional":false},{"reason":"used internally to parse the template string into AST","package":"babylon","optional":false}],"imports":[{"note":"Package has a CommonJS default export. ESM import works directly as default.","wrong":"const template = require('babel-template').default","symbol":"default","correct":"import template from 'babel-template'"},{"note":"In CJS, require returns the function directly, not an object with default property.","wrong":"const { default: template } = require('babel-template')","symbol":"default","correct":"const template = require('babel-template')"},{"note":"There is no named export 'template'. Use default import.","wrong":"import { template } from 'babel-template'","symbol":"template","correct":"import template from 'babel-template'"}],"quickstart":{"code":"import template from 'babel-template';\nimport generate from 'babel-generator';\nimport * as t from 'babel-types';\n\nconst buildRequire = template(`\n  var IMPORT_NAME = require(SOURCE);\n`);\n\nconst ast = buildRequire({\n  IMPORT_NAME: t.identifier('myModule'),\n  SOURCE: t.stringLiteral('my-module')\n});\n\nconsole.log(generate(ast).code);\n// var myModule = require('my-module');","lang":"javascript","description":"Shows how to create a template function using babel-template and invoke it with AST node replacements."},"warnings":[{"fix":"Migrate to @babel/template: npm install @babel/template --save-dev and update imports to import template from '@babel/template'.","message":"babel-template is only compatible with Babel 6. For Babel 7+, use @babel/template.","severity":"deprecated","affected_versions":">=6.0.0 <7.0.0"},{"fix":"Ensure placeholders are all uppercase or follow identifier rules; avoid using keywords.","message":"Template placeholders (e.g., IMPORT_NAME) must be valid JavaScript identifiers and must appear in the template exactly as they are used (case-sensitive).","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use @babel/template with @babel/parser for modern syntax support.","message":"babel-template relies on babylon (Babel 6 parser) which does not support all modern JavaScript syntax (e.g., optional chaining, nullish coalescing).","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install --save-dev babel-template' for Babel 6, or use '@babel/template' for Babel 7+.","cause":"Package not installed or wrong package name (e.g., Babel 7+ users might try to use this instead of @babel/template).","error":"Cannot find module 'babel-template'"},{"fix":"Use default import: import template from 'babel-template'.","cause":"Incorrect import attempt, e.g., import { template } from 'babel-template'.","error":"TypeError: template is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}