I have deployed a simple azure function written in typescript. And I keep getting this error after I deploy it . FailureException: Worker was unable to load function xyz: 'Cannot find module 'lodash'Require stack:- C:\home\site\wwwroot\dist\xyz\index.js
This is how my function.json file looks
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 10 * * *"
}
],
"scriptFile": "../dist/xyz/index.js"
}
And this is how my package.json file looks
{
"name": "xyz",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"build:production": "npm run prestart && npm prune --production",
"watch": "tsc --w",
"prestart": "npm run build",
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {
"@azure/functions": "^3.0.0",
"@azure/identity": "^2.0.4",
"@azure/keyvault-secrets": "^4.4.0",
"@types/node": "^18.7.18",
"axios": "^0.21.1",
"lodash": "^4.17.21",
"moment": "2.18.1",
"pg-promise": "^10.10.1",
"tslib": "^2.4.0",
"typescript": "^4.0.0"
},
"devDependencies": {
"@azure/functions": "^3.0.0",
"@azure/identity": "^2.0.4",
"@azure/keyvault-secrets": "^4.4.0",
"@types/node": "^18.7.18",
"axios": "^0.21.1",
"azure-cli": "^0.10.20",
"lodash": "^4.17.21",
"pg-promise": "^10.9.5",
"tslib": "^2.4.0",
"typescript": "^4.0.0"
}
}
And this is how I used it in index.ts file.
declare var require: any;
import { AzureFunction, Context } from '@azure/functions';
import {
differenceWith, forEach, get, groupBy, isEqual, keys, map,
set, size
} from 'lodash';
import * as moment from 'moment';
import * as pgPromise from 'pg-promise';
const axios = require('axios');
const pgp = pgPromise({});
I have tried multiple fixes from StackOverflow, but I still keep getting this error. Am I missing something here? Thanks.






