I am building a project with the Ionic framework and I want to integrate IPFS. I am trying to upload a file to IPFS...
The "ready" event is successfully triggered, but when adding a file the following error is thrown:
more is not a function
The code snipped in which I try to upload the file is:
const IPFS = require('ipfs');
const node = new IPFS();
node.on('error', error => {
console.error(error.message);
});
node.on('ready', () => {
node.files.add({
path: "HelloWorld.txt",
content: "Hello World!"
}, (err, filesAdded) => {
if (err)
console.error(err);
else
console.log("Success!");
});
});
Hey @WieFel do you have a stack trace? I've just tried your example code and I get the message Success! printed to the console.
Hello @alanshaw . Thanks for your help!
Here is the stacktrace:
columnNumber: 5
​
fileName: "http://localhost:8100/build/vendor.js"
​
lineNumber: 109836
​
message: "more is not a function"
​
stack: "reader@http://localhost:8100/build/vendor.js:109836:5
pull@http://localhost:8100/build/vendor.js:117886:7
module.exports@http://localhost:8100/build/vendor.js:329985:3
_addPullStream@http://localhost:8100/build/vendor.js:329668:7
addReadableStream@http://localhost:8100/build/vendor.js:329789:9
[437]/HomePage.prototype.uploadImage@http://localhost:8100/build/main.js:144:22
[437]/HomePage.prototype.sendData/<@http://localhost:8100/build/main.js:130:13
EventEmitter.prototype.emit@http://localhost:8100/build/vendor.js:45470:9
done@http://localhost:8100/build/vendor.js:296874:5
_parallel/<@http://localhost:8100/build/vendor.js:149342:9
once/<@http://localhost:8100/build/vendor.js:117992:9
replenish@http://localhost:8100/build/vendor.js:149607:25
iterateeCallback@http://localhost:8100/build/vendor.js:149596:17
onlyOnce/<@http://localhost:8100/build/vendor.js:79250:9
_parallel/</<@http://localhost:8100/build/vendor.js:149339:13
done@http://localhost:8100/build/vendor.js:303727:7
module.exports/</<@http://localhost:8100/build/vendor.js:303756:7
_parallel/<@http://localhost:8100/build/vendor.js:149342:9
once/<@http://localhost:8100/build/vendor.js:117992:9
replenish@http://localhost:8100/build/vendor.js:149607:25
iterateeCallback@http://localhost:8100/build/vendor.js:149596:17
onlyOnce/<@http://localhost:8100/build/vendor.js:79250:9
_parallel/</<@http://localhost:8100/build/vendor.js:149339:13
libp2p/<.start</gotConfig/<@http://localhost:8100/build/vendor.js:314564:11
_parallel/<@http://localhost:8100/build/vendor.js:149342:9
once/<@http://localhost:8100/build/vendor.js:117992:9
replenish@http://localhost:8100/build/vendor.js:149607:25
iterateeCallback@http://localhost:8100/build/vendor.js:149596:17
onlyOnce/<@http://localhost:8100/build/vendor.js:79250:9
_parallel/</<@http://localhost:8100/build/vendor.js:149339:13
start/</<@http://localhost:8100/build/vendor.js:328203:9
wrap/</<@http://localhost:8100/build/vendor.js:117926:13
run@http://localhost:8100/build/vendor.js:147696:13
runIfPresent@http://localhost:8100/build/vendor.js:147725:21
onGlobalMessage@http://localhost:8100/build/vendor.js:147765:17
F</l</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:15649
onInvokeTask@http://localhost:8100/build/vendor.js:6922:24
F</l</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:15562
F</c</r.prototype.runTask@http://localhost:8100/build/polyfills.js:3:10815
F</h</e.invokeTask@http://localhost:8100/build/polyfills.js:3:16787
p@http://localhost:8100/build/polyfills.js:2:27646
v@http://localhost:8100/build/polyfills.js:2:27893
"
I also have tried to use different node versions (v10.4.1, v8.9.4, v8.0.0) and I tried to downgrade the IPFS dependency, but without success... Always the same problem.
This stack trace looks like you're calling addReadableStream - do you have a link to the code you're running?
Yes, sorry. In the meantime I had changed my code. But the error when using addReadableStream was the same as for add. The code is:
uploadImage(node) {
const stream = node.files.addReadableStream(); //node contains the IPFS object
stream.on('error', (err) => {
console.log("Error: " + err);
});
stream.on('data', (file) => {
console.log("stream.on data!");
});
var file = {
path: `/home/felix/Ionic_Projects/bcsh-craftsman/`,
content: "test.txt"
};
stream.write(file);
stream.end();
}
The error is immediately thrown in the first line of the function uploadImage(), when addReadableStream() is called.
Today I get a different stacktrace:
TypeError: more is not a function[Learn More] index.js:78
reader index.js:78
pull pull.js:43
module.exports index.js:51
_addPullStream files.js:143
addReadableStream files.js:264
[472]/HomePage.prototype.uploadImage home.ts:59:19
[472]/HomePage.prototype.sendData/< home.ts:40:8
EventEmitter.prototype.emit events.js:78
done boot.js:69
_parallel/< parallel.js:39
once/< once.js:12
replenish eachOfLimit.js:61
iterateeCallback eachOfLimit.js:50
onlyOnce/< onlyOnce.js:12
_parallel/</< parallel.js:36
done start.js:20
module.exports/</< start.js:49
_parallel/< parallel.js:39
once/< once.js:12
replenish eachOfLimit.js:61
iterateeCallback eachOfLimit.js:50
onlyOnce/< onlyOnce.js:12
_parallel/</< parallel.js:36
libp2p/<.start</gotConfig/< libp2p.js:63
_parallel/< parallel.js:39
once/< once.js:12
replenish eachOfLimit.js:61
iterateeCallback eachOfLimit.js:50
onlyOnce/< onlyOnce.js:12
_parallel/</< parallel.js:36
start/</< index.js:254
wrap/</< setImmediate.js:27
run setImmediate.js:40
runIfPresent setImmediate.js:69
onGlobalMessage setImmediate.js:109
F</l</t.prototype.invokeTask http://localhost:8100/build/polyfills.js:3:15649
F</c</r.prototype.runTask http://localhost:8100/build/polyfills.js:3:10815
F</h</e.invokeTask http://localhost:8100/build/polyfills.js:3:16787
p http://localhost:8100/build/polyfills.js:2:27646
v http://localhost:8100/build/polyfills.js:2:27893
As I said, also when using node.files.add(), the error is the same.
node.files.add([{
path: './src/pages/home/test.txt',
content: Buffer.from('Hello World')
}], (err, files) => {
console.log('files', files);
}
);
Versions 0.29.0 and 0.28.0 of the ipfs package yield the same error...
Could you try content: Buffer.from("test.txt")? Otherwise, can I get access to this repo - I can't see where the issue might be from the code you've posted.
When I try content: Buffer.from("test.txt"), the same error occurs.
I can't give you access to the private repo, but here is the complete .ts file where the IPFS stuff is done:
https://gist.github.com/WieFel/1ff3d96d2f93013ac676300a8b553d96
@WieFel could you create an public repo with some example code I can _run_ that causes the error? I still can't see from the code where this might be going wrong.
I have set up a fresh Ionic project with a blank page (home.html) and added a button which triggers the IPFS code (which resides in home.ts). Still, the same error appears. It seems to be a problem related to TypeScript. My best guess is that TypeScript compiles the code relating to the Looper script somehow wrong.
To get the project running:
npm install -g ionic && npm install && npm run ionic:serve
within the project directory.
Do you have a link to the repo?
Did you forget to push, there's no code connecting to IPFS in there
I had already pushed it. Did you check TestIPFS/src/pages/home/home.ts ?

Ok now I pushed it. Sorry...
This looks to be a problem with the ionic bundling process - pull-write is getting version 3 of looper when it requires it even though it depends on version 4. Version 3 has a different API and does not return a function to call (more).
I was able to get this to work by adding <script src="https://unpkg.com/ipfs/dist/index.min.js"></script> before <script src="build/main.js"></script> in src/index.html and then instantiating IPFS like so:
const node = new (window as any).Ipfs();
I don't have time to look into why this is happening just now but if you decide to look into it then please post your findings here!
I have the same issue when I try start a node with ionic
Most helpful comment
This looks to be a problem with the ionic bundling process -
pull-writeis getting version 3 oflooperwhen it requires it even though it depends on version 4. Version 3 has a different API and does not return a function to call (more).I was able to get this to work by adding
<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>before<script src="build/main.js"></script>insrc/index.htmland then instantiating IPFS like so:I don't have time to look into why this is happening just now but if you decide to look into it then please post your findings here!