Well, this is probably a typescript question but it is also related to Azure:
In my Azure function Nodejs code:
import {
app,
HttpRequest,
HttpResponseInit,
InvocationContext,
} from "@azure/functions";
import { workerExec } from "./worker";
export async function myappfunction1(
request: HttpRequest,
context: InvocationContext
): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
try {
console.log(`Incoming event: ${JSON.stringify(event)}`);
const result = await workerExec(event, context);
console.log("Successfully processed event;");
return result;
} catch (err) {
console.log(err);
throw err;
}
}
app.http("myappfunction1", {
methods: ["GET", "POST"],
authLevel: "anonymous",
handler: myappfunction1,
});
I get this error when building with the tsc
command:
error TS2305: Module '"@azure/functions"' has no exported member 'app'.
error TS2724: '"@azure/functions"' has no exported member named 'HttpResponseInit'.
error TS2305: Module '"@azure/functions"' has no exported member 'InvocationContext'
Here is my tsconfig.json:
{
"compilerOptions": {
"target": "es2020",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": false,
"module": "es2015",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "src/functions",
"paths": {
"*": [
"*",
"node_modules/*"
]
},
},
"exclude": [
"node_modules",
"**/*.test.ts"
],
"include": [
"**/*"
]
}
what is wrong?
2
Answers
I fixed it by running:
I have reproduced the issue at my environment and got expected result
I have referred ms docs to create a function in v4 model using typescript.
Initially when I created the function, I was getting the error too.
My folder structure was
Then I executed
npm run build
command. Upon successful execution, it createddist
in my folder structure, where you can see your functions .js file has created. Because in mytsconfig
file, outDir is set to"outDir" : "dist"
.In your case, outDir is missing in your tsconfig file.
Then, it worked for me.
code:
local.setting.json:
tsconfig.json:
Output: