小编Gus*_*ord的帖子

Handlebars.compile 抛出异常“错误:您必须将字符串或 Handlebars AST 传递给 Handlebars.compile。你通过了 <html>...'

前提

我们在后端 nodejs 应用程序中运行了把手,用于对发送的各种消息进行模板化。

Handlebars.compile 抛出此异常(从部分编译模板时)

Error: You must pass a string or Handlebars AST to Handlebars.compile. You passed <html>
<head>
... extremely long markup
at Object.compile (/Users/guscrawford/rollick-management-console/deployd/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:501:11)
at HandlebarsEnvironment.hb.compile (/Users/guscrawford/rollick-management-console/deployd/node_modules/handlebars/dist/cjs/handlebars.js:39:40)
at Object.invokePartialWrapper [as invokePartial] (/Users/guscrawford/rollick-management-console/deployd/node_modules/handlebars/dist/cjs/handlebars/runtime.js:71:44)
... additional stack trace through to dpd, bluebird etc.
Run Code Online (Sandbox Code Playgroud)

不能通过隔离复制

继续尝试建立一个废品项目: yarn add handlebars handlebars-helper-ternary handlebars-helpers handlebars.numeral

然后在 nodejs 中运行这个脚本:

const   handlebars = require('handlebars'),
        numeralHelper = require('handlebars.numeral'),    
        ternaryHelper = require('handlebars-helper-ternary'),
        helpers = require('handlebars-helpers')({
        handlebars: handlebars
    });
console.log(`Testing...`);
const base = `
<html>
    <body style="font-family:'Segoe …
Run Code Online (Sandbox Code Playgroud)

javascript node.js handlebars.js deployd

0
推荐指数
1
解决办法
3440
查看次数

标签 统计

deployd ×1

handlebars.js ×1

javascript ×1

node.js ×1