davglass / license-checker

Check NPM package licenses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating JSON file using require method not working

Jabark opened this issue · comments

With this file:

const checker = require('license-checker');

checker.init({
    start: './',
    production: true,
    relativeLicensePath: true,
    json: true,
    out: './licenses.json',
}, (error, res) => {
    if (error) {
        console.error("Error:", error);
    } else {
        console.dir(res);
    }
});

And then running this command (given the above file is called licenses.js):

node licenses

I would expect a JSON file to be generated in the root of where I am running the command from, however no file is being generated. JSON is being output correctly in the console so it doesn't appear to be an issue with the other parts. I tried json: './licenses.json to no avail too.

Running license-checker --production --json > licenses.json --relativeLicensePath in the same location works as expected.

Same problem here. I checked the sourcecode and it seems to me, that the require call will not write the file from itself, that is only implemented for commandline call.

Same problem for me , it does not parseJson when customPath is use. Did you guys find any workarounds?

Like i wrote, the file is only written in the commandline call. You can write it manually with fs where Jabark is using console.dir(res); 🙂

I dont want the file to be written. It gives me error when I use customPath option else it works fine. The json object gets returned fine otherwise
The error is this.parseJson is not a function. Any idea???