简体   繁体   English

在Meteor中使用fs模块获取Uncaught TypeError _fs2.default.readFile不是一个函数

[英]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.

相关问题 TypeError:fs.​​readFile不是函数 - TypeError: fs.readFile is not a function 我收到此错误我想使用 javascript 代码读取文件未捕获的类型错误:fs.readFile 不是 function。 我收到此错误 - I am getting this error I want to readfile using javascript code Uncaught TypeError: fs.readFile is not a function. I am getting this error 未捕获的类型错误:fs_1.default.readFileSync 不是 function - Uncaught TypeError: fs_1.default.readFileSync is not a function 获取未捕获的类型错误:将 Browserify 与 Nutritionix NodeJS 客户端库一起使用时,fs.readdirSync 不是 function - Getting Uncaught TypeError: fs.readdirSync is not a function when using Browserify with Nutritionix NodeJS client library 将 Electron 与 React 一起使用时出现“未捕获的类型错误:fs.writeFile 不是函数” - “Uncaught TypeError: fs.writeFile is not a function” when using Electron with React 未捕获的类型错误:fs.writeFile 不是 function - Uncaught TypeError: fs.writeFile is not a function browserify:-未捕获的TypeError:fs.​​readFileSync不是函数 - browserify :- Uncaught TypeError: fs.readFileSync is not a function 未捕获的TypeError:fs.​​createWriteStream不是函数 - Uncaught TypeError: fs.createWriteStream is not a function 未捕获的TypeError:fs.​​readFileSync不是控制台中的函数 - Uncaught TypeError: fs.readFileSync is not a function in console fs.readFile() 或 fs.readFileSync() 不是函数异常,但为什么呢? - fs.readFile() or fs.readFileSync() not a function exception but why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM