简体   繁体   中英

Meteor, npm, and request

I'm using meteor and I ran npm install request to get access to that library. 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

<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)

#!/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). 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.

As for NPM request, you will not be able to:

  1. install it normally like you do in most node projects, so node_module is out/npm install require is out
  2. access the functions in it without a Npm.require

At this point you have two options: adding the package NPM from Atmosphere(unofficial package repository) and including request. Or try placing the lib into /packages/ and then using Npm.require('request').

Alternatively you can just use Meteor's built in HTTP package (meteor add http) which functions similar to request.

Remove from your template as it seems Meteor wants to create this tag for you when building the template. This should take care of the "bad formatting in HTML template" error in test.html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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