未定义Meteor / node-gd和ReferenceError:require

时间:2022-11-06 15:17:26

I have a few related questions about node-gd and Meteor.

我有一些关于node-gd和Meteor的相关问题。

First couple of questions. I've tried to install node-gd in what I believe is the correct place.

前几个问题。我试图在我认为正确的地方安装node-gd。

Does this look like I've installed it to the correct location for use with Meteor?

这看起来我是否已将其安装到与Meteor一起使用的正确位置?

Should I be worried about the warnings in the output?

我应该担心输出中的警告吗?

me@ubuntu:/usr/local/lib$ sudo npm install node-gd
npm http GET https://registry.npmjs.org/node-gd
npm http 304 https://registry.npmjs.org/node-gd

> node-gd@0.2.3 install /usr/local/lib/node_modules/node-gd
> node-gyp rebuild

make: Entering directory `/usr/local/lib/node_modules/node-gd/build'
CXX(target) Release/obj.target/node_gd/cpp/node-gd.o

../cpp/node-gd.cpp: In static member function ‘static v8::Handle<v8::Value> Gd::Image::StringFTBBox(const v8::Arguments&)’:
../cpp/node-gd.cpp:1045:22: warning: variable ‘color’ set but not used [-Wunused-but-set-variable]
   REQ_INT_ARG(0, color);
                  ^
../cpp/node-gd.cpp:41:7: note: in definition of macro ‘REQ_INT_ARG’
int VAR;                                                              \
   ^
SOLINK_MODULE(target) Release/obj.target/node_gd.node
SOLINK_MODULE(target) Release/obj.target/node_gd.node: Finished
COPY Release/node_gd.node
make: Leaving directory `/usr/local/lib/node_modules/node-gd/build'
node-gd@0.2.3 node_modules/node-gd
me@ubuntu:/usr/local/lib$ ls
node_modules  python2.7  python3.4
me@ubuntu:/usr/local/lib$ cd node_modules/
me@ubuntu:/usr/local/lib/node_modules$ ls
meteorite  node-gd

I am passing coordinates back to the server and I want to use node-gd to manipulate an image on the server.

我将坐标传递回服务器,我想使用node-gd来操作服务器上的图像。

This is my Meteor method:

这是我的Meteor方法:

Meteor.methods({
  createImage: function(coords) {
  console.log('createImage')
  console.log(coords.x);

  var gd   = require('gd');
  }
});

When I try to run this function I get this on my terminal:

当我尝试运行此功能时,我在终端上得到了这个:

I20140826-06:44:18.166(-7)? Exception while invoking method 'createImage' ReferenceError: require is not defined
I20140826-06:44:18.166(-7)?     at Meteor.methods.createImage (app/server/server.js:7:15)
I20140826-06:44:18.167(-7)?     at maybeAuditArgumentChecks (packages/livedata/livedata_server.js:1487)
I20140826-06:44:18.167(-7)?     at packages/livedata/livedata_server.js:643
I20140826-06:44:18.168(-7)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20140826-06:44:18.168(-7)?     at packages/livedata/livedata_server.js:642
I20140826-06:44:18.168(-7)?     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
I20140826-06:44:18.168(-7)?     at _.extend.protocol_handlers.method (packages/livedata/livedata_server.js:641)
I20140826-06:44:18.168(-7)?     at packages/livedata/livedata_server.js:541

The answer to this question suggests various JS solutions. Is this what I need, can anyone recommend what's best to use for Meteor for both server and client?

这个问题的答案提出了各种JS解决方案。这是我需要的,任何人都可以为服务器和客户端推荐最适合Meteor的东西吗?

2 个解决方案

#1


2  

You can't add NPM modules to meteor this way, you should use the npm atmosphere package from meteorhacks : http://atmospherejs.com/package/npm

你不能以这种方式将NPM模块添加到流星,你应该使用meteorhacks的npm氛围包:http://atmospherejs.com/package/npm

What you need to do is install the package via meteorite :

你需要做的是通过陨石安装包:

mrt add npm

Then add a packages.json in your project root and specify the node-gd dependency :

然后在项目根目录中添加packages.json并指定node-gd依赖项:

{
  "node-gd":"0.2.3"
}

Finally, in your server code use Meteor.require to access the node-gd API.

最后,在您的服务器代码中使用Meteor.require访问node-gd API。

Be aware though that Meteor server side programming uses Fibers so you'll have to wrap async API calls to node-gd using either Meteor._wrapAsync or the set of Async utilities that come with the npm atmosphere package.

请注意,Meteor服务器端编程使用Fibers,因此您必须使用Meteor._wrapAsync或npm氛围包附带的一组Async实用程序将异步API调用包装到node-gd。

Here is a nice article on understanding this point : https://www.discovermeteor.com/blog/understanding-sync-async-javascript-node/

以下是关于理解这一点的好文章:https://www.discovermeteor.com/blog/understanding-sync-async-javascript-node/

You can't use NPM packages on the client.

您不能在客户端上使用NPM包。

#2


0  

Try using Meteor.npmRequire('your module name')

尝试使用Meteor.npmRequire('你的模块名称')

#1


2  

You can't add NPM modules to meteor this way, you should use the npm atmosphere package from meteorhacks : http://atmospherejs.com/package/npm

你不能以这种方式将NPM模块添加到流星,你应该使用meteorhacks的npm氛围包:http://atmospherejs.com/package/npm

What you need to do is install the package via meteorite :

你需要做的是通过陨石安装包:

mrt add npm

Then add a packages.json in your project root and specify the node-gd dependency :

然后在项目根目录中添加packages.json并指定node-gd依赖项:

{
  "node-gd":"0.2.3"
}

Finally, in your server code use Meteor.require to access the node-gd API.

最后,在您的服务器代码中使用Meteor.require访问node-gd API。

Be aware though that Meteor server side programming uses Fibers so you'll have to wrap async API calls to node-gd using either Meteor._wrapAsync or the set of Async utilities that come with the npm atmosphere package.

请注意,Meteor服务器端编程使用Fibers,因此您必须使用Meteor._wrapAsync或npm氛围包附带的一组Async实用程序将异步API调用包装到node-gd。

Here is a nice article on understanding this point : https://www.discovermeteor.com/blog/understanding-sync-async-javascript-node/

以下是关于理解这一点的好文章:https://www.discovermeteor.com/blog/understanding-sync-async-javascript-node/

You can't use NPM packages on the client.

您不能在客户端上使用NPM包。

#2


0  

Try using Meteor.npmRequire('your module name')

尝试使用Meteor.npmRequire('你的模块名称')