加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – React Js需要’fs’

发布时间:2020-12-15 05:08:17 所属栏目:百科 来源:网络整理
导读:我有 import fs from 'fs' 在我的package.json我有 然后我运行命令 npm i fs fs@0.0.2 node_modules/fs 接下来在我的React商店中导入’fs’模块 import fs from 'fs' 但是当我尝试使用fs时 我没有看到除了构造函数和一些其他__methods之外的方法.我没有看到
我有
import fs from 'fs'

在我的package.json我有

然后我运行命令

>  npm i fs
>  fs@0.0.2 node_modules/fs

接下来在我的React商店中导入’fs’模块

import fs from 'fs'

但是当我尝试使用fs时

我没有看到除了构造函数和一些其他__methods之外的方法.我没有看到方法createReadStream或任何其他文件操作方法.

有人知道出了什么问题吗? (使用Webpack)并可根据要求提供更多信息,但我到目前为止……

ps:为什么我可以npm i fs – 当我在其他帖子上阅读时,我不必这样做(使用节点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’.你无法导入它.你必须找到解决这个问题的另一种方法.看到这张票. https://github.com/facebook/create-react-app/issues/3074

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读