AlexPshul / nxazure

MIT License
16 stars 7 forks source link

Empty dependencies field in package.json breaks build process #21

Closed JonSilver closed 1 year ago

JonSilver commented 1 year ago

So... I've been struggling to get an existing project into an nx monorepo and now I know why.

It's fairly natural to copy over all the existing code into a newly generated project, and cut and paste all of the function app's dependencies to the root package.json.

But if you don't leave an empty dependencies field in the function app project's package.json, the generator will fail to copy over the relevant dependencies during build. What's worse is there's no relevant error message either.

Steps to reproduce:

In an nx function app project created with @nxazure/func, delete the dependencies section completely. Try a build. It'll fail with the error message Cannot read properties of undefined (reading 'tsconfig-paths'), which isn't exactly helpful.

If you just include "dependencies": {}, then it'll work just fine, building and running smoothly.

I hope this bug report helps, @AlexPshul. Thanks again for all your hard work on this generator.

JonSilver commented 1 year ago

I surmise it's going wrong at lines 38 & 40 of packages/func/src/executors/common/get-copy-package-to-app-transformer-factory.ts where you're indexing into .dependencies. If it's not there, it's undefined. So inserting a simple check and setting dependencies to {} would fix it. I could submit a PR if you like @AlexPshul.

AlexPshul commented 1 year ago

That's quite a thorough investigation you did there. A PR to fix this would be very much welcome! :)

JonSilver commented 1 year ago

PR to fix this would be very much welcome! :)

I'll give it a go over the next couple of days 👍

AlexPshul commented 1 year ago

Thank you again for taking care of this :)