简体   繁体   English

流星,npm和请求

[英]Meteor, npm, and request

I'm using meteor and I ran npm install request to get access to that library. 我正在使用流星,并且运行了npm install请求来访问该库。 Everything seems to install correctly but when I run the meteor server, I then get the following error. 一切似乎都正确安装,但是当我运行流星服务器时,我得到以下错误。 Is there any word on why this is or how to solve it? 关于这是为什么还是如何解决有什么说法吗? Thanks. 谢谢。

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

For reference: 以供参考:

test.html 的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 (same) run.js(相同)

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

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

far.execute();

Meteor constructs the entire DOM itself so it will typically reject any script tags included in the html (but it will include scripts in the head, thanks Andrew). Meteor构造了整个DOM本身,因此通常会拒绝html中包含的任何脚本标签(但感谢Andrew,它将在头中包含脚本)。 It also only supports handlebars style templating (right now). 它还仅支持车把样式模板(现在)。

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

My advice would be to have your js and css located as files inside the client folder under your projects root. 我的建议是将您的js和CSS作为文件放在项目根目录下的client文件夹中。

As for NPM request, you will not be able to: 对于NPM请求,您将不能:

  1. install it normally like you do in most node projects, so node_module is out/npm install require is out 像在大多数节点项目中一样,通常进行安装,因此node_module已用完/ npm安装要求已用完
  2. access the functions in it without a Npm.require 无需Npm.require即可访问其中的功能

At this point you have two options: adding the package NPM from Atmosphere(unofficial package repository) and including request. 此时,您有两个选择:从Atmosphere(非官方软件包存储库)添加软件包NPM,并包含请求。 Or try placing the lib into /packages/ and then using Npm.require('request'). 或者尝试将库放入/ packages /,然后使用Npm.require('request')。

Alternatively you can just use Meteor's built in HTTP package (meteor add http) which functions similar to request. 另外,您可以只使用Meteor内置的HTTP程序包(meteor add http),其功能类似于request。

Remove from your template as it seems Meteor wants to create this tag for you when building the template. 从您的模板中删除,因为Meteor似乎希望在构建模板时为您创建此标签。 This should take care of the "bad formatting in HTML template" error in test.html. 这应该解决test.html中的“ HTML模板格式错误”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM