Meteor / React:ReferenceError:未定义require /错误:找不到模块

时间:2016-01-07 10:48:03

标签: javascript meteor reactjs npm require

我必须将Meteor和React用于学校项目。 我建立了一个网站,我想添加一个旋转木马。

为此,我尝试使用:https://github.com/vazco/meteor-universe-react-carousel/

使用示例脚本:

var React = require('react');
var Slider = require('react-slick');

var SimpleSlider = React.createClass({
  render: function () {
    var settings = {
      dots: true,
      infinite: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1
    };
    return (
      <Slider {...settings}>
        <div><h3>1</h3></div>
        <div><h3>2</h3></div>
        <div><h3>3</h3></div>
        <div><h3>4</h3></div>
        <div><h3>5</h3></div>
        <div><h3>6</h3></div>
      </Slider>
    );
  }
});

使用此代码,我得到:ReferenceError:require未定义(l1)

经过一番研究,我看到了几个对我不起作用的解决方案,比如使用Meteor.require或Npm.require。

我按照'require is not defined' in Meteor.js when including NPM package之类的链接 或Meteor cannot find module "module"

现在我有点迷失了这一点,我如何使用meteor add package导入的软件包?陨石是否已被弃用,我是否需要使用npm?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

<iframe style='border: 0;border-width: 0px;' scrolling='no' frameborder='0' width='320' height='300' src='https://www.youtube.com/embed/2B_QP9JGD7Q'></iframe>

Meteor包被导出到全局命名空间,并且可以像包var styles = StyleSheet.create({ centerText: { marginBottom:5, textAlign: 'center', }, noResultsText: { marginTop: 70, marginBottom:0, color: '#000000', }, sourceRow: { justifyContent: 'space-around', flexDirection: 'row', }, rowText: { textAlign: 'left', color: 'white', fontSize: 12, marginLeft: 5, fontFamily: 'SFCompactText-Medium' }, detailText: { fontFamily: 'SFCompactText-Light', fontSize: 18, color: 'white', textAlign: 'left', marginTop: 2, marginLeft: 5, }, touchCard: { margin: 3, width: window.width*0.95, shadowOffset: {width: 2, height: 2}, shadowOpacity: 0.5, shadowRadius: 3, alignSelf:'center', }, card: { flex: 1, width: window.width*0.98, alignSelf:'center', }, heartText: { color: 'white', fontSize: 12, fontWeight: 'bold', alignSelf: 'center', fontFamily: 'SFCompactText-Medium' }, heartRow: { flexDirection: 'row', justifyContent: 'space-around', alignSelf: 'center', justifyContent: 'center', }, logoBtn: { height: window.width/10, width: window.width/10, alignSelf:'center', }, heartBtn: { height: (92/97)*(window.width/13), width: window.width/13, alignSelf:'center', }, category: { fontFamily: 'Bebas Neue', fontSize: 10, fontWeight: 'bold' }, header: { flex: 1, justifyContent: 'space-around', marginTop: window.height/60, }, footer: { flex: 1, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', margin: window.height/80, }, container: { flex: 1, backgroundColor: '#1a1a1a', }, videoPreview: { flex: 2, height: window.width*0.85, width:window.width*0.98, flexDirection: 'column' }, previewText: { fontFamily: 'Bebas Neue', fontSize: 23, color: 'white', textAlign: 'left', marginTop: 2, marginLeft: 5, }, }); 文件中声明的那样提供给客户端和/或服务器。 Meteor 1.3中将提供模块支持。如果不添加支持require语法的其他包,则无法在文档中使用该示例,例如how can I use a package imported with meteor add package和/或package.js