Meteor 找不到模块“module" [英] Meteor cannot find module "module"
问题描述
我正在尝试在流星中安装 Spooky 模块(这个在我的公共文件夹中: app/public/node_modules).
I'm trying to install the Spooky module in meteor (this one is in my public folder: app/public/node_modules).
我已阅读答案在这篇文章中 并在 server/server.js 中添加了以下代码
I've read answers in this post and added the following code in server/server.js
Meteor.startup ->
path = Npm.require 'path'
fs = Npm.require 'fs'
base = path.resolve '.'
isBundle = fs.existsSync base + '/bundle'
modulePath = base + (if isBundle then '/bundle/static' else '/public') + '/node_modules'
spooky = Npm.require modulePath + '/spooky'
但是当我运行流星时,我得到:
But when I'm running meteor I get:
Error: Cannot find module '/Users/mac/Documents/websites/app/.meteor/local/build/programs/server/public/node_modules/spooky'
推荐答案
您需要创建一个智能包才能在您的应用中使用 Npm 模块.或者你可以使用meteor-npm.
You need to create a smart package to use Npm modules in your app. Alternatively you can use meteor-npm.
您不能将 Npm.require
单独用于非标准 npm 模块,例如 spooky.
You can't use Npm.require
on its own for non standard npm modules like spooky.
如果你使用meteor-npm,你可以用meteite 安装它:mrt add npm
If you use meteor-npm you can install it with meteorite: mrt add npm
然后使用 Meteor.require("spooky")
代替,在您将模块添加到您的 packages.json 之后.您可以在此处查看更多详细信息:http://meteorhacks.com/complete-npm-integration-for-meteor.html.
Then use Meteor.require("spooky")
instead, after you have added the module to your packages.json. You can have a look here for more details: http://meteorhacks.com/complete-npm-integration-for-meteor.html.
官方的做法是制作自己的智能包来包装npm模块.有这样一个包的例子:https://github.com/avital/meteor-xml2js-npm-demo
The official way to do it is to make your own smart package to wrap the npm module in. There is an example of such a package: https://github.com/avital/meteor-xml2js-npm-demo
该示例使用 xml2js 作为 npm 模块,但您可以交换名称以使其变得诡异.
The example uses xml2js as the npm module, but you could swap the names around so its spooky instead.
然后你可以把这个包添加到你的/packages
文件夹中(比如名称spooky
),然后用meteor add spooky将它添加到你的meteor项目中代码>.
Then you can add this package into your /packages
folder (say with the name spooky
), and add it to your meteor project with meteor add spooky
.
aircraft.meteor.com 上的包有更多这样的例子,它们几乎做同样的事情(例如 stripe (https://atmosphere.meteor.com/package/stripe)).
The packages on atmosphere.meteor.com have more examples of this, they pretty much do the same thing (e.g stripe (https://atmosphere.meteor.com/package/stripe)).
这篇关于Meteor 找不到模块“module"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!