Ipfs
IPFS API 導入和 ReactJS
我正在將 IPFS 集成到 ReactJS 前端以將文本儲存在 IPFS 中(然後是要儲存在區塊鏈上的地址)。我有一個超出我經驗的導入錯誤,希望有人能提供幫助。
錯誤 -
IpfsAPI VM153:1 Uncaught ReferenceError: IpfsAPI is not defined at eval (eval at evaluate (:85:21), <anonymous>:1:1) at Object.<anonymous> (http://jenbil.com:3000/static/js/bundle.js:32851:24) at Object.<anonymous> (http://jenbil.com:3000/static/js/bundle.js:33301:31) at __webpack_require__ (http://jenbil.com:3000/static/js/bundle.js:556:30) at fn (http://jenbil.com:3000/static/js/bundle.js:87:20) at Object.<anonymous> (http://jenbil.com:3000/static/js/bundle.js:10871:13) at __webpack_require__ (http://jenbil.com:3000/static/js/bundle.js:556:30) at fn (http://jenbil.com:3000/static/js/bundle.js:87:20) at Object.<anonymous> (http://jenbil.com:3000/static/js/bundle.js:591:19) at __webpack_require__ (http://jenbil.com:3000/static/js/bundle.js:556:30)
進口通常像其他人出現的那樣工作,例如
Web3 function Web3(provider) { this._requestManager = new RequestManager(provider); this.currentProvider = provider; this.eth = new Eth(this); this.db = new DB(this); this.shh = ne…
我有這個程式碼 -
import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import Web3 from 'web3' import _ from 'lodash' import { Navbar, Jumbotron, Button } from 'react-bootstrap'; import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table'; import IpfsAPI from 'ipfs-api'
我的節點模組中有 ipfs -
root@ubuntu-512mb-nyc3-01:/usr/share/nginx/html/ipfs/node_modules# ls ipfs* ipfs-api: CHANGELOG.md CONTRIBUTING.md examples LICENSE package.json src circle.yml dist gulpfile.js node_modules README.md ipfs-block: circle.yml dist LICENSE package.json README.md src ipfs-unixfs: circle.yml dist LICENSE package.json README.md src test
這是我的 package.json
root@ubuntu-512mb-nyc3-01:/usr/share/nginx/html/ipfs# more package.json { "name": "zillerium", "version": "0.1.0", "private": true, "dependencies": { "bootstrap": "^3.3.7", "lodash": "^4.17.4", "react": "^15.4.2", "react-bootstrap": "^0.30.8", "react-bootstrap-dropdown": "^0.3.0", "react-bootstrap-table": "^3.2.1", "react-dom": "^15.4.2", "web3": "^0.18.4" }, "devDependencies": { "react-scripts": "0.9.5" }, "dependencies": { "ipfs-api": "^14.0.0" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }
還有我的 index.js -
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css/bootstrap-theme.css'; import 'react-bootstrap-table/dist/react-bootstrap-table-all.min.css'; import IpfsAPI from 'ipfs-api' ReactDOM.render( <App />, document.getElementById('root') );
可能存在節點模組未正確安裝的可能性。請檢查您的 node_modules 目錄。
嘗試使用 require 看看你是否再次面臨同樣的問題
常量 ipfsApi=require(‘ipfs-api’);
不過,如果您遇到同樣的問題,則節點模組安裝不正確。