Hello.
Site Url : https://stci-mini-test.netlify.app/
I am building a scheduled function to poll from external service every hour ( even though in this example I am configuring it to run every minute for testing purposes ).
The project is built with no errors, the scheduled function is read correctly by the Functions tab in netlify ( the path to the function is /api/test ).
import { NextApiRequest, NextApiResponse } from 'next'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
console.log(req)
res.status(200).send({})
return {
statusCode: 200,
}
}
export default handler
export const config = {
type: 'experimental-scheduled',
schedule: '* * * * *',
}
At first I had some issures with the middleware auth logic as it was blocking the scheduled requests to the api so I commented out all the logic to test it.
Now the function log is showing the error down below on every call.
As far as I understand netlify is calling a path that does not exist
.netlify/functions-internal/_api_test-handler
Jun 26, 04:19:01 PM: 2023-06-26T15:19:01.030Z undefined ERROR Uncaught Exception {āerrorTypeā:āRuntime.ImportModuleErrorā,āerrorMessageā:āError: Cannot find module āfollow-redirectsā\nRequire stack:\n- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.js\n- /var/task/_api_test-handler.js\n- /var/runtime/index.mjsā,āstackā:[āRuntime.ImportModuleError: Error: Cannot find module āfollow-redirectsāā,āRequire stack:ā,ā- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.jsā,ā- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.jsā,ā- /var/task/_api_test-handler.jsā,ā- /var/runtime/index.mjsā," at _loadUserApp (file:///var/runtime/index.mjs:997:17)ā,ā at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)ā,ā at async start (file:///var/runtime/index.mjs:1195:23)ā,ā at async file:///var/runtime/index.mjs:1201:1"]}Jun 26, 04:19:01 PM: Unknown application error occurred
Runtime.ImportModuleErrorJun 26, 04:19:01 PM: 37d08802 Duration: 202.11 ms Memory Usage: 17 MB Jun 26, 04:19:02 PM: 2023-06-26T15:19:02.270Z undefined ERROR Uncaught Exception {āerrorTypeā:āRuntime.ImportModuleErrorā,āerrorMessageā:āError: Cannot find module āfollow-redirectsā\nRequire stack:\n- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.js\n- /var/task/_api_test-handler.js\n- /var/runtime/index.mjsā,āstackā:[āRuntime.ImportModuleError: Error: Cannot find module āfollow-redirectsāā,āRequire stack:ā,ā- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.jsā,ā- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.jsā,ā- /var/task/_api_test-handler.jsā,ā- /var/runtime/index.mjsā," at _loadUserApp (file:///var/runtime/index.mjs:997:17)ā,ā at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)ā,ā at async start (file:///var/runtime/index.mjs:1195:23)ā,ā at async file:///var/runtime/index.mjs:1201:1"]}Jun 26, 04:19:02 PM: Unknown application error occurred
Runtime.ImportModuleErrorJun 26, 04:19:02 PM: 868de1fc Duration: 200.01 ms Memory Usage: 18 MB Jun 26, 04:19:02 PM: INIT_START Runtime Version: nodejs:18.v7 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:26e9402591d9c467cdcc7355f843d61968f36ecb6e9ef5ab253cc21163343275Jun 26, 04:19:02 PM: 2023-06-26T15:19:02.509Z undefined ERROR Uncaught Exception {āerrorTypeā:āRuntime.ImportModuleErrorā,āerrorMessageā:āError: Cannot find module āfollow-redirectsā\nRequire stack:\n- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.js\n- /var/task/_api_test-handler.js\n- /var/runtime/index.mjsā,āstackā:[āRuntime.ImportModuleError: Error: Cannot find module āfollow-redirectsāā,āRequire stack:ā,ā- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.jsā,ā- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.jsā,ā- /var/task/_api_test-handler.jsā,ā- /var/runtime/index.mjsā," at _loadUserApp (file:///var/runtime/index.mjs:997:17)ā,ā at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)ā,ā at async start (file:///var/runtime/index.mjs:1195:23)ā,ā at async file:///var/runtime/index.mjs:1201:1"]}Jun 26, 04:19:03 PM: 2023-06-26T15:19:03.931Z undefined ERROR Uncaught Exception {āerrorTypeā:āRuntime.ImportModuleErrorā,āerrorMessageā:āError: Cannot find module āfollow-redirectsā\nRequire stack:\n- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.js\n- /var/task/_api_test-handler.js\n- /var/runtime/index.mjsā,āstackā:[āRuntime.ImportModuleError: Error: Cannot find module āfollow-redirectsāā,āRequire stack:ā,ā- /var/task/.netlify/functions-internal/_api_test-handler/handlerUtils.jsā,ā- /var/task/.netlify/functions-internal/_api_test-handler/_api_test-handler.jsā,ā- /var/task/_api_test-handler.jsā,ā- /var/runtime/index.mjsā," at _loadUserApp (file:///var/runtime/index.mjs:997:17)ā,ā at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)ā,ā at async start (file:///var/runtime/index.mjs:1195:23)ā,ā at async file:///var/runtime/index.mjs:1201:1"]}Jun 26, 04:19:03 PM: Unknown application error occurred
Runtime.ImportModuleErrorJun 26, 04:19:03 PM: 4690a8f5 Duration: 197.70 ms Memory Usage: 18 MB
[ UPDATE ]
I run other tests on that api endpoint ( /api/test )
I added some logic to do side effect ( add a test document in my mongodb database )
The build shows that /api/test is redirected to /404
3:27:26 PM: { from: '/api/test', to: '/404.html', status: 404 }
and the docs says that a scheduled function canāt be invoked with the url (Scheduled Functions | Netlify Docs)
But in my case when I enter https://stci-mini-test.netlify.app/api/test I get the 404 as intended however the side-effect runs and I get a new document in my database is that normal ?