Tôi cóReact Js require 'fs'
import fs from 'fs'
và trong package.json của tôi, tôi có
Sau đó, tôi chạy lệnh
> npm i fs
> [email protected] node_modules/fs
tiếp theo trong cửa hàng React của tôi Tôi nhập mô-đun 'fs'
import fs from 'fs'
Tuy nhiên khi tôi cố gắng sử dụng fs
tôi không thấy các phương pháp trừ constructor và một vài __methods khác. Tôi không thấy phương thức createReadStream hoặc bất kỳ phương thức thao tác tệp nào khác.
Có ai biết điều gì sai không? (sử dụng Webpack) và có thể cung cấp thêm thông tin theo yêu cầu, nhưng tôi nhận được thông tin này ...
ps: tại sao tôi có thể npm i fs - lưu khi đọc trên các bài đăng khác mà tôi không có để làm điều đó (sử dụng nút 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
},
.
.
.
.
})
Có thể có hai mặt của http://stackoverflow.com/questions/24594796/node-js-npm-install-fs-error. fs là một phần của các mô-đun lõi nút. –
Bạn đang mong đợi điều gì sẽ xảy ra ở đây? 'fs' là mô-đun nút hoạt động với hệ thống tệp. Hầu hết các phương pháp của nó sẽ không hoạt động trong trình duyệt. –
Ồ, tôi hiểu rồi .... tôi nghĩ mình có thể đưa vào bất kỳ gói nút nào trong ứng dụng phản ứng của mình ... vậy có tương đương với Javascript không? – joe