{"id":26586,"library":"vip-template-compiler","title":"Vue Template Compiler","description":"Vue 2.0 template compiler that pre-compiles Vue templates into render functions, avoiding runtime compilation and CSP restrictions. Version 2.0.6 is the current stable release for Vue 2.x, maintained by the Vue core team. Use cases include build tools like vue-loader and vueify. Differentiator: provides AST access and compile-time options (custom modules/directives) unlike higher-level tools. Note: Not needed for most users; use vue-loader or vueify instead.","status":"maintenance","version":"2.0.6","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","vue","compiler"],"install":[{"cmd":"npm install vip-template-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add vip-template-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add vip-template-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - compiled templates expect Vue runtime, but not a strict dependency at compile time","package":"vue","optional":true}],"imports":[{"note":"Uses CommonJS; ESM import may cause issues. Default import works if configured.","wrong":"import compiler from 'vue-template-compiler'","symbol":"compiler","correct":"const compiler = require('vue-template-compiler')"},{"note":"Direct method import for compile with options.","wrong":null,"symbol":"compile","correct":"const { compile } = require('vue-template-compiler')"},{"note":"Returns instantiated functions; not CSP-compliant.","wrong":null,"symbol":"compileToFunctions","correct":"const { compileToFunctions } = require('vue-template-compiler')"},{"note":"Parses .vue SFC files into descriptors.","wrong":null,"symbol":"parseComponent","correct":"const { parseComponent } = require('vue-template-compiler')"}],"quickstart":{"code":"const compiler = require('vue-template-compiler');\nconst template = '<div>{{ message }}</div>';\nconst result = compiler.compile(template);\nconsole.log(result.render);\n// Output: render function code (string) with `with(this)`\nconst compiled = compiler.compileToFunctions(template);\n// compiled.render is a Function\nconsole.log(compiled.render);","lang":"javascript","description":"Demonstrates basic usage of compile() and compileToFunctions() methods."},"warnings":[{"fix":"Either avoid strict mode or use compileToFunctions which returns a function usable in strict mode (but uses new Function() and is not CSP-compliant).","message":"Generated render function uses `with` and thus cannot be used in strict mode code.","severity":"gotcha","affected_versions":"*"},{"fix":"Use compile() output (string) with a CSP-compliant eval strategy, or pre-compile via build tools.","message":"compileToFunctions() uses new Function() which violates CSP (Content Security Policy) restrictions.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `import { compile } from 'vue-template-compiler'` with @types/vue installed.","message":"Incorrect import path for TypeScript: 'vue-template-compiler' does not ship type definitions; types are under 'vue/types/compiler'.","severity":"broken","affected_versions":"*"},{"fix":"Migrate to @vue/compiler-sfc for Vue 3.","message":"For Vue 3 projects, this package is not compatible; use @vue/compiler-sfc instead.","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install via `npm install vue-template-compiler` and use with Node.js or a bundler (Webpack/Rollup).","cause":"Package not installed or used in a browser context without bundler.","error":"Cannot find module 'vue-template-compiler'"},{"fix":"Use compileToFunctions() instead, which returns a function without 'with' statement.","cause":"Using compile() output in strict mode JavaScript (e.g., ES modules in strict mode).","error":"Uncaught Error: 'with' statement is not allowed in strict mode"},{"fix":"Use `const { compileToFunctions } = require('vue-template-compiler')`.","cause":"Wrong import: imported default instead of named export.","error":"TypeError: compiler.compileToFunctions is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}