kessler / license-report

create a short report about a project's dependencies (license, url etc)
MIT License
226 stars 39 forks source link

TypeError: Cannot read property 'email' of undefined; author feature not fully working #50

Closed bobo96run closed 3 years ago

bobo96run commented 3 years ago

Hi,

Thank you for this tool!

When running it on some projects, I have this error:

<my-project>/node_modules/license-report/lib/getPackageReportData.js:57
                        if (author.email) { author = author + ' ' + author.email; }
                                   ^

TypeError: Cannot read property 'email' of undefined
    at <my-project>/node_modules/license-report/lib/getPackageReportData.js:57:15
    at <my-project>/node_modules/license-report/lib/getPackageJson.js:22:3
    at Stubborn.p._onTaskExecuted (<my-project>/node_modules/stubborn/lib/Stubborn.js:71:18)
    at wrapper (<my-project>/node_modules/lodash/lodash.js:4949:19)
    at <my-project>/node_modules/lodash/lodash.js:10076:25
    at Request._callback (<my-project>/node_modules/license-report/lib/getPackageJson.js:55:11)
    at Request.self.callback (<my-project>/node_modules/request/request.js:185:22)
    at Request.emit (events.js:314:20)
    at Request.<anonymous> (<my-project>/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:314:20)

It appears that some projects have an author field like this in their package.json:

"author": "<some-email>",

(e.g. react-hook-form: https://github.com/react-hook-form/react-hook-form/blob/v7.0.4/package.json#L64)

which translates likes this in the registry:

{ "email": "some-email" }

The failing line has been introduced by https://github.com/ironSource/license-report/pull/29

https://github.com/ironSource/license-report/blob/a48a7e78dfc63144f3e9d951594a21fd1f6ec480/lib/getPackageReportData.js#L54-L59

So in case the dependency specifies only an email, but no name, this creates the exception.

However, this also shows that even in case the author object does have a name field, the next 2 lines will be useless as we modify the author variable to be now the name string, i.e. it is no longer the author object.

We can indeed see in the report (when it works) that there is never an email nor a URL appended to the author name.

BePo65 commented 3 years ago

this bug should be fixed by pr #46.

BePo65 commented 3 years ago

Closing as PR #46 is merged into master and waiting for the next release