【问题标题】:Meteor, npm, and requestMeteor、npm 和请求
【发布时间】:2013-11-09 02:18:57
【问题描述】:

我正在使用流星并运行 npm install request 以访问该库。一切似乎都安装正确,但是当我运行流星服务器时,我收到以下错误。有什么关于为什么会这样或如何解决它的消息吗?谢谢。

While building the application:
node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template
node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js:1:15: Unexpected token ILLEGAL
node_modules/request/node_modules/form-data/node_modules/combined-stream/test/run.js:1:15: Unexpected token ILLEGAL

供参考:

test.html

<html>
  <head>
    <style>
      div {
        font-family: monospace;
        font-size: 8pt;
      }
      div.log {color: #444;}
      div.warn {color: #550;}
      div.error {color: #800; font-weight: bold;}
    </style>
    <script src="../uuid.js"></script>
  </head>
  <body>
    <script src="./test.js"></script>
  </body>
</html>

run.js(相同)

#!/usr/bin/env node
var far = require('far').create();

far.add(__dirname);
far.include(/test-.*\.js$/);

far.execute();

【问题讨论】:

  • test.html 长什么样子?
  • 在 cmets 中添加。
  • 如果删除stylescript 标签会怎样?你为什么要添加这样的脚本呢?你应该把它留给 Meteor。

标签: node.js meteor npm


【解决方案1】:

Meteor 自己构建整个 DOM,因此它通常会拒绝包含在 html 中的任何脚本标签(但它会在头部包含脚本,感谢 Andrew)。它也只支持把手样式模板(现在)。

<html>
  <head>
  <title>Something</title>
  </head>
  <body>
    {{>yourHandlebarsTemplate}}
  </body>
</html>

我的建议是将您的 js 和 css 作为文件放在项目根目录下的客户端文件夹中。

对于 NPM 请求,您将无法:

  1. 像在大多数节点项目中一样正常安装它,因此 node_module 已退出/npm install require 已退出
  2. 无需 Npm.require 即可访问其中的函数

此时您有两个选择:从 Atmosphere(非官方包存储库)添加包 NPM 并包含请求。或者尝试将 lib 放入 /packages/,然后使用 Npm.require('request')。

或者你可以使用 Meteor 的内置 HTTP 包(meteor add http),它的功能类似于请求。

【讨论】:

  • 太棒了,这太棒了。谢谢彭特。
  • 你绝对可以手动包含&lt;script&gt;标签,至少在&lt;head&gt;中。
  • 我对@9​​87654325@ 模块有同样的问题(它与HTML/脚本无关......那部分完全不相关)。您能否详细说明为什么无法use it like other npm modules with Meteor
【解决方案2】:

从您的模板中删除,因为 Meteor 似乎想在构建模板时为您创建此标签。这应该会处理 test.html 中的“HTML 模板中的错误格式”错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-11
    • 2016-04-23
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2013-03-13
    • 2015-05-05
    • 2016-01-12
    相关资源
    最近更新 更多