[英]Using fs module in Meteor getting Uncaught TypeError _fs2.default.readFile is not a function
Hi i am trying to test the fs module in my Meteor project. 嗨,我正在尝试测试我的Meteor项目中的fs模块。 I am using Meteor 1.3 new es2015 modules.
我正在使用Meteor 1.3新的es2015模块。 I'm trying to use nodes fs module to read a file.
我正在尝试使用节点fs模块来读取文件。 tried a few methods but seem to be getting this same error when i run myFunc() in browser.
尝试了一些方法,但是当我在浏览器中运行myFunc()时似乎遇到了同样的错误。
Uncaught TypeError: _fs2.default.readFile is not a function 未捕获的TypeError:_fs2.default.readFile不是函数
import fs from 'fs'
myFunc = function(){
fs.readFile('input.txt', function(err, data){
if(err)
console.log("Error" + err)
console.log("Data from input" + data)
})
}
I think you can't use fs
module in the browser. 我想你不能在浏览器中使用
fs
模块。 There is a separate npm module for fs
in the browser called fs-web
. 有一个单独的NPM模块
fs
在浏览器中名为fs-web
。 After installing this using npm install fs-web --save
, you can use it by importing it in the client side files like this, 使用
npm install fs-web --save
,您可以通过在客户端文件中导入它来使用它,如下所示,
import * as fs from 'fs-web';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.