Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

"ReferenceError: https is not defined" when add data to infura. #959

Closed
iheqi opened this issue Mar 26, 2019 · 6 comments
Closed

"ReferenceError: https is not defined" when add data to infura. #959

iheqi opened this issue Mar 26, 2019 · 6 comments

Comments

@iheqi
Copy link

iheqi commented Mar 26, 2019

Description

When I call the add method to upload data to infura, I got an error.

import ipfsClient from 'ipfs-http-client';

let ipfs = ipfsClient("ipfs.infura.io", "5001", { protocol: "https" });

function saveImageToIpfs() {
  const data = Buffer.from('test', 'utf-8');
  ipfs.add(data).then(res => {
    console.log(res);
  });
}

saveImageToIpfs();

Expected behavior

console the result:

[
    {
        hash: "QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm"
        path: "QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm"
        size: 12
    }
]

Actual behavior

I got an error:

index.browser.js:17 Uncaught (in promise) ReferenceError: https is not defined
    at getRequest (index.browser.js:17)
    at requestAPI (send-request.js:202)
    at send (send-request.js:231)
    at eval (send-files-stream.js:104)
    at Function.eval (add.js:59)
    at eval (index.js:39)
    at new Promise (<anonymous>)
    at eval (index.js:34)
    at Object.eval [as add] (add.js:81)
    at saveImageToIpfs (config.js:21)
    at _callee$ (Create.js:17)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:288)
    at Generator.prototype.(anonymous function) [as next] (webpack-internal:///./node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:114:21)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)
    at eval (asyncToGenerator.js:32)
    at new Promise (<anonymous>)
    at Object.eval (asyncToGenerator.js:21)
    at Object.eval [as beforeUpload] (Create.js:7)
    at Object.Upload._this.beforeUpload (Upload.js:266)
    at AjaxUploader.upload (AjaxUploader.js:106)
    at eval (AjaxUploader.js:74)
    at Array.forEach (<anonymous>)
    at AjaxUploader._this.uploadFiles (AjaxUploader.js:71)
    at AjaxUploader._this.onChange (AjaxUploader.js:36)
    at HTMLUnknownElement.callCallback (react-dom.development.js:147)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
    at invokeGuardedCallback (react-dom.development.js:250)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
    at executeDispatch (react-dom.development.js:571)
    at executeDispatchesInOrder (react-dom.development.js:596)
    at executeDispatchesAndRelease (react-dom.development.js:695)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:704)
    at forEachAccumulated (react-dom.development.js:676)
    at runEventsInBatch (react-dom.development.js:844)
    at runExtractedEventsInBatch (react-dom.development.js:852)
    at handleTopLevel (react-dom.development.js:5030)
    at batchedUpdates$1 (react-dom.development.js:21270)
    at batchedUpdates (react-dom.development.js:2247)
    at dispatchEvent (react-dom.development.js:5110)
getRequest @ index.browser.js:17
requestAPI @ send-request.js:202
send @ send-request.js:231
(anonymous) @ send-files-stream.js:104
(anonymous) @ add.js:59
(anonymous) @ index.js:39
(anonymous) @ index.js:34
(anonymous) @ add.js:81
saveImageToIpfs @ config.js:21
_callee$ @ Create.js:17
tryCatch @ runtime.js:62
invoke @ runtime.js:288
prototype.(anonymous function) @ runtime.js:114
asyncGeneratorStep @ asyncToGenerator.js:3
_next @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ Create.js:7
Upload._this.beforeUpload @ Upload.js:266
upload @ AjaxUploader.js:106
(anonymous) @ AjaxUploader.js:74
AjaxUploader._this.uploadFiles @ AjaxUploader.js:71
AjaxUploader._this.onChange @ AjaxUploader.js:36
callCallback @ react-dom.development.js:147
invokeGuardedCallbackDev @ react-dom.development.js:196
invokeGuardedCallback @ react-dom.development.js:250
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:265
executeDispatch @ react-dom.development.js:571
executeDispatchesInOrder @ react-dom.development.js:596
executeDispatchesAndRelease @ react-dom.development.js:695
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:704
forEachAccumulated @ react-dom.development.js:676
runEventsInBatch @ react-dom.development.js:844
runExtractedEventsInBatch @ react-dom.development.js:852
handleTopLevel @ react-dom.development.js:5030
batchedUpdates$1 @ react-dom.development.js:21270
batchedUpdates @ react-dom.development.js:2247
dispatchEvent @ react-dom.development.js:5110
Promise.then (async)
saveImageToIpfs @ config.js:21
_callee$ @ Create.js:17
tryCatch @ runtime.js:62
invoke @ runtime.js:288
prototype.(anonymous function) @ runtime.js:114
asyncGeneratorStep @ asyncToGenerator.js:3
_next @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ Create.js:7
Upload._this.beforeUpload @ Upload.js:266
upload @ AjaxUploader.js:106
(anonymous) @ AjaxUploader.js:74
AjaxUploader._this.uploadFiles @ AjaxUploader.js:71
AjaxUploader._this.onChange @ AjaxUploader.js:36
callCallback @ react-dom.development.js:147
invokeGuardedCallbackDev @ react-dom.development.js:196
invokeGuardedCallback @ react-dom.development.js:250
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:265
executeDispatch @ react-dom.development.js:571
executeDispatchesInOrder @ react-dom.development.js:596
executeDispatchesAndRelease @ react-dom.development.js:695
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:704
forEachAccumulated @ react-dom.development.js:676
runEventsInBatch @ react-dom.development.js:844
runExtractedEventsInBatch @ react-dom.development.js:852
handleTopLevel @ react-dom.development.js:5030
batchedUpdates$1 @ react-dom.development.js:21270
batchedUpdates @ react-dom.development.js:2247
dispatchEvent @ react-dom.development.js:5110

But it work well in local ipfs:

let ipfs = ipfsClient('localhost', '5002', { protocol: 'http' });

Versions

  • js-ipfs-http-client: ^30.1.0
@alanshaw
Copy link
Contributor

@hugomrdias this is the issue reported here hugomrdias/iso-stream-http#1

@hugomrdias
Copy link
Contributor

@alanshaw
Copy link
Contributor

@iheqi can you please reinstall ipfs-http-client to get the latest version of iso-stream-http and verify this has now been fixed?

@iheqi
Copy link
Author

iheqi commented Mar 27, 2019

@iheqi can you please reinstall ipfs-http-client to get the latest version of iso-stream-http and verify this has now been fixed?

Yes, it work now. Thank you guys.

@AK-007
Copy link

AK-007 commented Mar 28, 2019

@alanshaw @hugomrdias
I am using ipfs cdn

<script src="https://unpkg.com/ipfs-http-client@30.1.0/dist/index.js"></script>

I am still getting the error "ReferenceError: https is not defined" when using

var ipfs = window.IpfsHttpClient({ host:'ipfs.infura.io', port: '5001', protocol: "https" });

What should I do?

@alanshaw
Copy link
Contributor

Please use https://unpkg.com/ipfs-http-client@30.1.1/dist/index.js

lidel added a commit to ipfs/ipfs-companion that referenced this issue Apr 8, 2019
This fixes regresssion of #654 introduced by js-ipfs-http-client
ipfs-inactive/js-ipfs-http-client#959

Closes #706
lidel added a commit to ipfs/ipfs-companion that referenced this issue Apr 8, 2019
This fixes regresssion of #654 introduced by js-ipfs-http-client
ipfs-inactive/js-ipfs-http-client#959

Closes #706
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants