0

我正在使用 Meteor 1.13(最新版本),他们最近添加了 NPM 支持。所以我在 Lob.com NPM 中添加了。我开始做一个字母函数,我得到这个错误:

未捕获的类型错误: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);
    });

}


});

我试过手动包含'fs',但没有运气......我试过:

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');

这些都不起作用!任何关于这里发生的事情的帮助都会有所帮助..谢谢!

4

1 回答 1

0

所以你们大多数人可能都知道.. fs 仅在节点中可用,而不是在前端。

所以我没有在服务器中包含我的 Meteor.Method 所以它有文件权限问题。一旦我将它移动到服务器文件夹中,那就太好了!

于 2016-05-27T22:05:05.180 回答