'require is not defined' in Meteor.js when including NPM package

╄→гoц情女王★ 提交于 2019-12-05 16:59:41

Meteor.require is a function added by the meteor npm smart package, which actually doesn't do much for using npm other than wrapping some asynchronous callbacks. It's a few months old, so you might want to try using Meteor's Npm.require directly in case something broke.

The monkey-patching of the Meteor global by this package is misleading.

Making comments above an answer.

Is Meteor.require() a typo? That is what is in your code though your question text refers to the correct Npm.require().

I think module.exports is there for non-meteor use of the same file. Within meteor variables for export should be

  1. declared as globals inside the package
  2. exported with api.export() within the package.js file.

The documentation on this is a bit rough but look at namespacing and writing packages. Also looking into the various meteor packages on github is very useful.

Make sure you're using the meteor-npm package.

https://www.npmjs.com/package/meteor-npm

Use Npm.require() in meteor.

Like this:

var fs = Npm.require("fs");

For that you need to have a Meteor package: meteorhacks:npm , npm-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!