【问题标题】:Integrating Lob Node API wrapper with MeteorJs - Issue with require('fs')将 Lob 节点 API 包装器与 MeteorJs 集成 - require('fs') 的问题
【发布时间】:2016-05-27 16:46:44
【问题描述】:

我正在使用 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');

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

【问题讨论】:

    标签: javascript node.js meteor npm lob


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 1970-01-01
      • 2015-11-07
      • 2023-02-19
      • 1970-01-01
      • 2021-05-28
      • 2013-09-08
      • 2020-02-25
      • 2017-10-25
      相关资源
      最近更新 更多