Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.28k stars 423 forks source link

func start for new Node runtime doesn't build TS projects before trying to start #3320

Open diberry opened 1 year ago

diberry commented 1 year ago

I'm following the commandline quickstart for the new Node runtime from inside a VSCode typescript dev container. I've installed core tools (4.0.5085) and @azure/functions (^4.0.0-alpha.1). I did choose Ts instead of Js when creating the app but I didn't think it would matter. The npm scripts has the correct start and prestart to build tsc.

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "dist/src/functions/*.js",
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "prestart": "npm run build",
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "@azure/functions": "^4.0.0-alpha.1"
  },
  "devDependencies": {
    "azure-functions-core-tools": "^4.x",
    "@types/node": "18.x",
    "typescript": "^4.0.0"
  }
}

I created the local HTTP function which was successful and updated the file to include my own route.

import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";

export async function myhttptrigger(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log(`Http function processed request for url "${request.url}"`);

    const name = request.query.get('name') || await request.text() || 'world';

    return { body: `Hello, ${name}!` };
};

app.http('myhttptrigger', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    route: 'myroute',                                        //   <-- only change to file
    handler: myhttptrigger
});

Start the function with func start.

Core tools is looking for *.js but the build isn't working so no JS files. Why isn't the build getting called? If I build first then start the function, it works.

node ➜ /workspaces/typescript-node-3/LocalFunctionProj $ func help httptrigger

The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. 

Programming model v4 for Node is currently in preview. The goal of this model is to introduce a more intuitive and idiomatic way of authoring Function triggers and bindings for JavaScript and TypeScript developers. Learn more http://aka.ms/AzFuncNodeV4. node ➜ /workspaces/typescript-node-3/LocalFunctionProj $ func start

Azure Functions Core Tools
Core Tools Version:       4.0.5085 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.16.4.20366

[2023-03-27T14:14:20.835Z] Worker was unable to load entry point "dist/src/functions/*.js": Found zero files matching the supplied pattern
[2023-03-27T14:14:22.259Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
[2023-03-27T14:14:27.115Z] Host lock lease acquired by instance ID '00000000000000000000000063742850'.

image

ejizba commented 1 year ago

@diberry The build will happen automatically if you run npm start, or if you F5 from VS Code, but it won't happen automatically if you run func start - this is by design

diberry commented 1 year ago

@ejizba I ran npm start - you can see from the screenshot the tsc or npm build wasn't called for the npm start command.

ejizba commented 1 year ago

I'm seeing func start in your screenshot, not npm start