@Jim Burke Looks like the module is not correctly installed. Please make sure that you have installed the module in D:\home\site\wwwroot
directory and please verify that node_modules
is created and verify whether your package is installed correctly as documented here. Node 16 is in the preview and only supported in 4.x function runtime.
Can't get node-fetch to work (my first Azure function)
Hi,
I am writing my first Azure function in node.js. I would like to post a result to a URL, I would like to use Node Fetch. However, when I try to include the fetch function with
const fetch = require('node-fetch');
The function fails with:
HTTP response code
500 Internal Server Error
and an error in the log:
FailureException: Error: Cannot find module 'node-fetch'
I have used the shell to run npm
, and npm install node-fetch
and both are successful. I have set the function to run in Node V 16.
Is there anything I am doing obviously wrong?
Regards
Azure Functions
-
MayankBargali-MSFT 70,936 Reputation points Moderator
2022-02-21T07:46:31.327+00:00
1 additional answer
Sort by: Most helpful
-
Jim Burke 26 Reputation points
2022-02-21T17:02:29.09+00:00 It looks like
node-fetch
is not compatible withrequires
in this version of Node (v16), it works withimports
but that requires the azure function to betype: module
which I don't think can be achieved. I have solved this by usingaxios
which does work withrequires
in this version.