React Js需要'fs' [英] React Js require 'fs'
问题描述
我有
import fs from 'fs'
在我的package.json中,
and in my package.json I have
然后我运行命令
> npm i fs
> fs@0.0.2 node_modules/fs
接下来在我的React商店中,我导入"fs"模块
next in my React store I import 'fs' module
import fs from 'fs'
但是,当我尝试使用fs
However when I try to use fs
除了构造函数和其他一些__method之外,我看不到其他方法.我看不到方法createReadStream或任何其他文件操作方法.
I don't see methods except for constructor and a few other __methods. I don't see the method createReadStream or any other file manipulation methods.
有人知道出什么问题了吗? (使用Webpack),并且可以根据要求提供更多信息,但是我已经走得很远了……
Does anybody know what is wrong? (using Webpack) and can give more information upon request, but I am getting this far...
ps:为什么当我阅读其他我不必这样做的帖子(使用节点5.5.0)时,为什么我可以nfs fs --save
ps: why is it that I can npm i fs --save when I read on other posts that I do not have to do that (using node 5.5.0)
import Reflux from 'reflux'
import AddItemActions from '../actions/AddItemActions'
import request from 'superagent-bluebird-promise'
import fs from 'fs'
var ImageStore = Reflux.createStore({
init(){
.
.
.
},
decryptImage(file) {
var reader = new FileReader();
var info = {}
reader.onload = (output) => {
debugger
request.post("https://camfind.p.mashape.com/image_requests")
.set("X-Mashape-Key", "KEY")
.set("Content-Type", "application/x-www-form-urlencoded")
.set("Accept", "application/json")
.send({'focus': { 'x': 480}})
.send({'focus': { 'y': 640}})
.send({'image_request': {'altitude': 27.912109375}})
.send({'image_request': {'language': "en"}})
.send({'image_request': {'latitude': 35.8714220766008}})
.send({'image_request': {'locale' : "en_US"}})
.send({'image_request': {'longitude': 14.3583203002251}})
.send({'image_request': {'image': fs.createReadStream("/path" + 'file.jpg')}})
.then(function (result) {
console.log(result.status, result.headers, result.body);
this.info = result
},
function(error) {
console.log(error);
})
}
reader.readAsDataURL(file);
return info
},
.
.
.
.
})
推荐答案
在create-react-app
中,它们将'fs'存根.您不能导入它.
他们这样做是因为fs
是节点核心模块.
您必须找到该问题的另一种解决方案.参见此票证.
In create-react-app
they have stubbed out 'fs'. You cannot import it.
They did this because fs
is a node core module.
You'll have to find another solution to that problem. See this ticket.
这篇关于React Js需要'fs'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!