I am running into a problem using lambda functions:
create a new netlify project, and create a single netlify function file /netlify/functions/ipfsTest.ts :
import { Handler } from "@netlify/functions";
import { create } from "ipfs-core"
const handler: Handler = async (event) => {
const ipfs = await create();
return {
statusCode: 200,
body: JSON.stringify({ message: ipfs.toString() }),
};
};
export { handler };
Run netlify functions:serve
and go to the URL for the function ipfsTest, and you may get
Error - Cannot find module ‘./fetch.node’ Require stack: - /Users/zipzap/Dev/crypto/ipfsFunctionsTest/.netlify/functions-serve/ipfsTest/src/netlify/functions/ipfsTest.js - /Users/zipzap/Dev/crypto/ipfsFunctionsTest/.netlify/functions-serve/ipfsTest/ipfsTest.js - /Users/zipzap/.config/yarn/global/node_modules/lambda-local/build/lambdalocal.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/lib/functions/runtimes/index.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/lib/functions/registry.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/lib/functions/server.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/commands/dev/dev.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/commands/dev/index.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/commands/main.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/src/commands/index.js - /Users/zipzap/.config/yarn/global/node_modules/netlify-cli/bin/run
I believe that the ‘./fetch.node’ is referring to the file ipfs-core/src/http/fetch.node.js, but for whatever reason, when it is run as a lambda function, it does not build or load the file properly.
Here is the contents of my package.json:
{
"name": "ipfsFunctionsTest",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {},
"dependencies": {
"@netlify/functions": "^1.0.0",
"ipfs-core": "^0.15.4"
}
}
Anybody have any ideas?
this happens both with the ipfs-core
module, and the ipfs-http-client
module.
I have been trying to figure this out all day, and I am about to throw in the towel!