vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.13k stars 287 forks source link

Error when using @azure/ms-rest-nodeauth #820

Open martin-fuhrer opened 2 years ago

martin-fuhrer commented 2 years ago

We updated one of our projects from @zeit/ncc to @vercel/ncc and get a runtime error "TypeError: Cannot read property 'split' of undefined" since then. I could nail it down to a function import from @azure/ms-rest-nodeauth.

The attached file contains a minimal project demonstrating the error. To reproduce it, please execute these commands:

tar xvzf ncc-test.tar.gz cd ncc-test npm i npm run build node dist/index.js --> the error message is displayed

When going back to @zeit/ncc, the error doesn't occur anymore:

npm uninstall @vercel/ncc npm i @zeit/ncc npm run build node dist/index.js --> the expected output "function" is displayed

ncc-test.tar.gz

styfle commented 2 years ago

That is strange. When you remove the minify command, you can see the error is coming from axios trying to split a package.json without a version prop https://github.com/axios/axios/blob/5112ba3ee1cdd287638f4cc81d7dd0edaf67ca15/lib/helpers/validator.js#L15

The workaround is adding a version property to your package.json

alaingiller commented 2 years ago

It is interesting, but how it can works with @zeit/ncc then ? The dependencies are the same and the package.json too.

styfle commented 2 years ago

It seems like its resolving the wrong package.json here

https://github.com/axios/axios/blob/5112ba3ee1cdd287638f4cc81d7dd0edaf67ca15/lib/helpers/validator.js#L3

It doesn't fail when using JS source, only TS source so that makes me think the baseUrl in tsconfig.json is causing the issue.

cc @guybedford

guybedford commented 2 years ago

If it's just the _resolved, _integrity and _from fields that are different, those are metadata markers added by npm, so it could be a metadata difference. Or are there other fields diffing apart from those?

styfle commented 2 years ago

@guybedford In this case, its not just the private fields, its actually the wrong package.json (it uses the root package.json from the cwd instead of node_modules/axios/package.json)