简体   繁体   English

Meteor 1.3导入npm模块问题

[英]Meteor 1.3 import npm module issue

This seems simple enough but can't seem work it out following the guide for using npm using Npm packages Meteor 1.3 I meteor install the moment npm module. 这似乎很简单,但似乎无法按照使用Npm 使用npm软件包的指南Meteor 1.3我流星安装时刻npm模块。

Then when i try to use the package in the client I keep getting. 然后,当我尝试在客户端使用该包时,我会继续。

import moment from 'moment';
var Moment = require('moment')()

Template.myTemp.events({
'click #exampleBtn': function(e){

e.preventdefault()

console.log(Moment)

  }
});

In the console I seem to be getting SyntaxError: import declarations may only appear at top level of a module. 在控制台中,我似乎得到了SyntaxError:import声明可能只出现在模块的顶层。 ReferenceError: moment is not defined. ReferenceError:未定义时刻。

You already import moment from 'moment' , you don't need line #2. 你已经import moment from 'moment' ,你不需要第2行。 Essentially, line #1 and line #2 are the same. 基本上,第1行和第2行是相同的。

Line #1 is ES2015 module syntax. 第1行是ES2015模块语法。 Line #2 is CommonJS module syntax. 第2行是CommonJS模块语法。

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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