AlexPshul / nxazure

MIT License
16 stars 7 forks source link

Example in the README does not work #35

Closed DanielBertocci closed 1 month ago

DanielBertocci commented 1 month ago

I tried to set up a new workspace with this plugin following the readme provided here.

If I follow literally the steps, nx run my-new-app:start fails because the naming chosen for the functions "my-new-app" and "my-new-func" generates a function with invalid names.

Expand here to see the console error ### Console Error ```console > nx run my-new-app:start [my-new-app] my-new-app/src/functions/my-new-func.ts:3:23 - error TS7010: 'my', which lacks return-type annotation, implicitly has an 'any' return type. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:25 - error TS1005: '(' expected. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:29 - error TS1109: Expression expected. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:30 - error TS2304: Cannot find name 'func'. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:35 - error TS2552: Cannot find name 'request'. Did you mean 'Request'? 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~~~~~~ node_modules/@nxazure/func/node_modules/typescript/lib/lib.dom.d.ts:19046:13 19046 declare var Request: { 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~~~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:64 - error TS1005: ',' expected. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:84 - error TS1005: ';' expected. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:86 - error TS2365: Operator '>' cannot be applied to types 'boolean' and '{ context: any; "": any; const: any; return: { body: string; }; }'. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 context.log(`Http function processed request for url "${request.url}"`); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... 8 return { body: `Hello, ${name}!` }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 }; ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:3:94 - error TS2693: 'HttpResponseInit' only refers to a type, but is being used as a value here. 3 export async function my-new-func(request: HttpRequest, context: InvocationContext): Promise { ~~~~~~~~~~~~~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:4:5 - error TS18004: No value exists in scope for the shorthand property 'context'. Either declare one or provide an initializer. 4 context.log(`Http function processed request for url "${request.url}"`); ~~~~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:4:12 - error TS1005: ',' expected. 4 context.log(`Http function processed request for url "${request.url}"`); ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:4:61 - error TS2552: Cannot find name 'request'. Did you mean 'Request'? 4 context.log(`Http function processed request for url "${request.url}"`); ~~~~~~~ node_modules/@nxazure/func/node_modules/typescript/lib/lib.dom.d.ts:19046:13 19046 declare var Request: { ~~~~~~~ 'Request' is declared here. [my-new-app] my-new-app/src/functions/my-new-func.ts:4:76 - error TS1005: ',' expected. 4 context.log(`Http function processed request for url "${request.url}"`); ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:6:11 - error TS1005: ':' expected. 6 const name = request.query.get('name') || await request.text() || 'world'; ~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:6:11 - error TS2588: Cannot assign to 'name' because it is a constant. 6 const name = request.query.get('name') || await request.text() || 'world'; ~~~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:6:18 - error TS2552: Cannot find name 'request'. Did you mean 'Request'? 6 const name = request.query.get('name') || await request.text() || 'world'; ~~~~~~~ node_modules/@nxazure/func/node_modules/typescript/lib/lib.dom.d.ts:19046:13 19046 declare var Request: { ~~~~~~~ 'Request' is declared here. [my-new-app] my-new-app/src/functions/my-new-func.ts:6:53 - error TS2552: Cannot find name 'request'. Did you mean 'Request'? 6 const name = request.query.get('name') || await request.text() || 'world'; ~~~~~~~ node_modules/@nxazure/func/node_modules/typescript/lib/lib.dom.d.ts:19046:13 19046 declare var Request: { ~~~~~~~ 'Request' is declared here. [my-new-app] my-new-app/src/functions/my-new-func.ts:6:78 - error TS1005: ',' expected. 6 const name = request.query.get('name') || await request.text() || 'world'; ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:8:12 - error TS1005: ':' expected. 8 return { body: `Hello, ${name}!` }; ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:8:39 - error TS1005: ',' expected. 8 return { body: `Hello, ${name}!` }; ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:14:5 - error TS2322: Type 'number' is not assignable to type 'HttpHandler'. 14 handler: my-new-func ~~~~~~~ node_modules/@azure/functions/types/http.d.ts:17:5 17 handler: HttpHandler; ~~~~~~~ The expected type comes from property 'handler' which is declared here on type 'HttpFunctionOptions' [my-new-app] my-new-app/src/functions/my-new-func.ts:14:14 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. 14 handler: my-new-func ~~ [my-new-app] my-new-app/src/functions/my-new-func.ts:14:20 - error TS1109: Expression expected. 14 handler: my-new-func ~ [my-new-app] my-new-app/src/functions/my-new-func.ts:14:21 - error TS2304: Cannot find name 'func'. 14 handler: my-new-func ~~~~ [my-new-app] message TS6194: Found 26 errors. Watching for file changes. ```

If I use a name without dashes though (e.g. myfunc) it works.

I would recommend to change the example and then, if possible, to handle that case ;-)

AlexPshul commented 1 month ago

Oops, that should not happen! Thank you for the heads up. I really appreciate it. I'll keep the issue open as to track the fix to this.

AlexPshul commented 1 month ago

Hmmm turns out that this is how the func core tools work and generate the files. I updated the README file to avoid build error on quick start.

Thanks again for bringing this to my attention. I appreciate you taking the time to let me know.