关于javascript:使用我的Node.JS应用,获取模板已预编译为带有较新版本的Handlebars错误?

Getting template was precompiled with a newer version of Handlebars error with my Node.JS app?

我正在尝试创建一个使用开源Alpaca Forms程序包的Node.JS应用程序:

http://www.alpacajs.org/

我正在使用节点版本:v0.10.25

当我从教程中运行测试页时:

http://www.alpacajs.org/tutorial.html

使用该教程中找到的第二个示例页面:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
        <link type="text/css" href="//code.cloudcms.com/alpaca/1.5.17/bootstrap/alpaca.min.css" rel="stylesheet" />
        <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js">
        <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js">
        <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js">
        <script type="text/javascript" src="//code.cloudcms.com/alpaca/1.5.17/bootstrap/alpaca.min.js">
    </head>
    <body>
       
        <script type="text/javascript">
            $(document).ready(function() {
                $("#form").alpaca({
                   "schema": {
                       "title":"User Feedback",
                       "description":"What do you think about Alpaca?",
                       "type":"object",
                       "properties": {
                           "name": {
                               "type":"string",
                               "title":"Name"
                            },
                           "feedback": {
                               "type":"string",
                               "title":"Feedback"
                            },
                           "ranking": {
                               "type":"string",
                               "title":"Ranking",
                               "enum":['excellent','ok','so so']
                            }
                        }
                    }
                });
            });
       
    </body>
</html>

我在Chrome调试器控制台中遇到以下两个错误,抱怨我使用的模板是使用比当前运行时新的版本的Handlebars编译的,没有像SO指定的大多数报告问题那样旧。以下是Chrome调试器控制台中的错误转储:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Uncaught Error: Template was precompiled with a newer version of Handlebars than the current runtime.
Please update your runtime to a newer version (>= 4.0.0).
    Exception @ handlebars.js:2520
    checkRevision @ handlebars.js:2693
    template @ handlebars.js:2709
    hb.template @ handlebars.js:196
    (anonymous function) @ alpaca.min.js:1
    (anonymous function) @ alpaca.min.js:1
    (anonymous function) @ alpaca.min.js:1

Uncaught TypeError: $(...).alpaca is not a function
    (anonymous function) @ (index):14
    j @ jquery-1.11.1.min.js:2
    k.fireWith @ jquery-1.11.1.min.js:2
    m.extend.ready @ jquery-1.11.1.min.js:2
    J @ jquery-1.11.1.min.js:2

我与NPM进行了检查,并且使用的把手版本高于4.0.0:

1
2
$ npm ls | grep handlebars
└─┬ handlebars@4.0.5

看来错误消息是错误的吗?

我发现了这两个相关的SO帖子:

模板已使用比当前运行时更早版本的Handlebars进行了预编译

未捕获的错误:模板已与旧版本的车把进行了预编译

但是我没有使用Gulp或Ember.JS,所以我不知道所提供的补救措施是否适用于我的情况。

这是我根据NPM安装的软件包的列表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
npm ls
/home/roschler
├─┬ express@4.13.4
│ ├─┬ accepts@1.2.13
│ │ ├─┬ mime-types@2.1.10
│ │ │ └── mime-db@1.22.0
│ │ └── negotiator@0.5.3
│ ├── array-flatten@1.1.1
│ ├── content-disposition@0.5.1
│ ├── content-type@1.0.1
│ ├── cookie@0.1.5
│ ├── cookie-signature@1.0.6
│ ├─┬ debug@2.2.0
│ │ └── ms@0.7.1
│ ├── depd@1.1.0
│ ├── escape-html@1.0.3
│ ├── etag@1.7.0
│ ├─┬ finalhandler@0.4.1
│ │ └── unpipe@1.0.0
│ ├── fresh@0.3.0
│ ├── merge-descriptors@1.0.1
│ ├── methods@1.1.2
│ ├─┬ on-finished@2.3.0
│ │ └── ee-first@1.1.1
│ ├── parseurl@1.3.1
│ ├── path-to-regexp@0.1.7
│ ├─┬ proxy-addr@1.0.10
│ │ ├── forwarded@0.1.0
│ │ └── ipaddr.js@1.0.5
│ ├── qs@4.0.0
│ ├── range-parser@1.0.3
│ ├─┬ send@0.13.1
│ │ ├── destroy@1.0.4
│ │ ├─┬ http-errors@1.3.1
│ │ │ └── inherits@2.0.1
│ │ ├── mime@1.3.4
│ │ ├── ms@0.7.1
│ │ └── statuses@1.2.1
│ ├── serve-static@1.10.2
│ ├─┬ type-is@1.6.12
│ │ ├── media-typer@0.3.0
│ │ └─┬ mime-types@2.1.10
│ │   └── mime-db@1.22.0
│ ├── utils-merge@1.0.0
│ └── vary@1.0.1
└─┬ handlebars@4.0.5
  ├── async@1.5.2
  ├─┬ optimist@0.6.1
  │ ├── minimist@0.0.10
  │ └── wordwrap@0.0.3
  ├─┬ source-map@0.4.4
  │ └── amdefine@1.0.0
  └─┬ uglify-js@2.6.2
    ├── async@0.2.10
    ├── source-map@0.5.3
    ├── uglify-to-browserify@1.0.2
    └─┬ yargs@3.10.0
      ├── camelcase@1.2.1
      ├─┬ cliui@2.1.0
      │ ├─┬ center-align@0.1.3
      │ │ ├─┬ align-text@0.1.4
      │ │ │ ├─┬ kind-of@3.0.2
      │ │ │ │ └── is-buffer@1.1.3
      │ │ │ ├── longest@1.0.1
      │ │ │ └── repeat-string@1.5.4
      │ │ └── lazy-cache@1.0.3
      │ ├─┬ right-align@0.1.3
      │ │ └─┬ align-text@0.1.4
      │ │   ├─┬ kind-of@3.0.2
      │ │   │ └── is-buffer@1.1.3
      │ │   ├── longest@1.0.1
      │ │   └── repeat-string@1.5.4
      │ └── wordwrap@0.0.2
      ├── decamelize@1.2.0
      └── window-size@0.1.0

如何解决这些错误?


在示例HTML中,需要更新通过script标签包含的Handlebars库。当它指的是运行时库时,您需要更新您明确包含的JS库,而不是NPM包(通常)。

1
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js">

实际上应该包括一个4.0.0版本。例如

1
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.0/handlebars.js">