我使用Meteor 1.13(最新版本)并且他们最近添加了NPM支持。所以我在Lob.com NPM中添加了。我开始写一个字母函数,我得到了这个错误:
未捕获的TypeError:fs.readdirSync不是函数
这就是我的功能:
import { Meteor } from 'meteor/meteor';
import 'lob';
Meteor.methods({
sendLetter(name) {
Lob.letters.create({
description: 'Garrison Snelling',
to: {
name: name,
address_line1: '123 Test Street',
address_city: 'Mountain View',
address_state: 'CA',
address_zip: '94041',
address_country: 'US',
},
from: {
name: 'Ami Wang',
address_line1: '123 Test Avenue',
address_city: 'Mountain View',
address_state: 'CA',
address_zip: '94041',
address_country: 'US',
},
file: '<html style="padding-top: 3in; margin: .5in;">HTML Letter for {{name}}</html>',
data: {
name: 'Harry'
},
color: true
}, function (err, res) {
console.log(err, res);
})
.then(function (res) {
console.log('The Lob API responded with this letter object: ', res);
});
}
});
我已经尝试过包括&#f;&#39; fs&#39;手动,但没有运气...我已经尝试过:
var fs = require('fs'); // Didn't fail, but got same error
const fs = require('fs'); // Didn't fail, but got same error
var fs = Npm.require('fs'); // Didn't fail, but got same error
var fs = npm.require('fs'); // Failed
var fs = Meteor.require('fs');
这些都不起作用!任何关于这里发生的事情的帮助都会有所帮助..谢谢!
答案 0 :(得分:0)
因此,大多数人可能都知道.. fs仅在节点中可用而不是前端。
所以我没有在服务器中包含我的Meteor.Method,因此它有文件权限问题。一旦我将它移到服务器文件夹中,就可以了!