I have
import fs from 'fs'
在我的 package.json 中我有
然后我运行命令
> npm i fs
> [email protected] /cdn-cgi/l/email-protection node_modules/fs
接下来在我的 React 商店中导入“fs”模块
但是当我尝试使用 fs 时
除了构造函数和其他一些 __methods 之外,我没有看到其他方法。我没有看到 createReadStream 方法或任何其他文件操作方法。
有人知道出了什么问题吗? (使用 Webpack)并且可以根据要求提供更多信息,但我已经走到这一步了......
ps:为什么当我读到其他帖子时我可以 npm i fs --save 我不必这样做(使用节点 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
},
.
.
.
.
})
In create-react-app
他们已经删除了“fs”。您无法导入它。
他们这样做是因为fs
是节点核心模块。
您必须找到该问题的另一种解决方案。看这张票。 https://github.com/facebook/create-react-app/issues/3074
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)