【发布时间】:2016-04-16 14:38:33
【问题描述】:
我正在尝试使用 Node 构建演示应用程序,但在尝试使用 Nutrionix NodeJS 客户端库时,我不断收到 Uncaught TypeError: fs.readdirSync is not a function 错误 (https://github.com/nutritionix/nodejs-client-library)和浏览器化。
我正在关注本教程 http://www.sitepoint.com/getting-started-browserify/ 直到 使用 Browserify 输出 部分,但我没有使用 Underscore 和为 main.js 提供的代码,而是使用 Nutritionix NodeJS 客户端库和 main.js 中的以下代码:
var NutritionixClient = require('nutritionix');
var nutritionix = new NutritionixClient({
appId: '7c710fbd',
appKey: 'a2f106128aa4b2ab81fd783fca5bf0ee'
// debug: true, // defaults to false
});
我使用 Jade 的 HTML 如下:
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
script(src='javascripts/nutri.js')
script(src='javascripts/main.js')
我在命令行中使用以下内容通过 Nutritionix 构建一个新的 JavaScript 文件:
browserify public/javascripts/main.js -o public/javascripts/nutri.js
当我在本地运行时,在控制台中,我在 nutri.js 的第 465 行收到 Uncaught TypeError: fs.readdirSync is not a function,这是 Browserify 制作的文件。该行是以下函数中的第四行:
function readDirp(path, excludeList) {
var lib = {};
var expand = new Expander(path);
var files = fs.readdirSync(path).map(expand);
files.forEach(function(file){
if (excluded(file.name, excludeList) === false) {
lib[file.name.split('.').shift()] = require(file.location);
}
});
return lib;
}
我不确定为什么我不断收到此错误。当我浏览我在顶部链接的 Browserify 教程时,让 Browserified 文件工作没有问题。如果需要我提供更多信息,请告诉我,非常感谢任何帮助。
【问题讨论】:
标签: javascript jquery node.js pug browserify