You are here
Home > Technology > Troubleshooting > pdf-parse ERROR 05-versions-space.pdf

pdf-parse ERROR 05-versions-space.pdf

If you are using pdf-parse which is an excellent pdf-parsing library, you may run into a weird error:

Error: ENOENT: no such file or directory, open ‘./test/data/05-versions-space.pdf’

This error comes because of the following code in the npm module

let isDebugMode = !module.parent; 

//process.env.AUTO_KENT_DEBUG


//for testing purpose
if (isDebugMode) {
    
    let PDF_FILE = './test/data/05-versions-space.pdf';
    let dataBuffer = Fs.readFileSync(PDF_FILE);
    Pdf(dataBuffer).then(function(data) {
        Fs.writeFileSync(`${PDF_FILE}.txt`, data.text, {
            encoding: 'utf8',
            flag: 'w'
        });
        debugger;
    }).catch(function(err) {
        debugger;
    });

}

There are open pull requests, but the maintainer is not merging it. The simplest workaround, if you are using serverless is:

1. Copy /node_modules/pdf_parse/test/data/05-versions-space.pdf to the root of your project inside Root_Directory/test/data

2. Include it in your serverless

package:
    include:
        - test/**

That’s it! You are good to go.

0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
himanshu dinkar
himanshu dinkar
15 days ago

but what in the production side of it?

Top
2
0
Would love your thoughts, please comment.x
()
x