Skip to content

version loading throws an error when bundled #88

@mfulton26

Description

@mfulton26

I'm using prest-client in a project that bundles code using Webpack and the following line throws:

lib.version = JSON.parse(fs.readFileSync(__dirname + '/package.json')).version;

I've created a patch locally using yarn but others might run into this too. Node.js and Webpack support importing package.json directly which should be well supported by other bundlers that support Node.js:

diff --git a/index.js b/index.js
index 0f5fe1cb2b9ce459711f1eb29eaa002405f0fd60..e77aed24d74cf5b5eb3e3c9a4d14b2631516ce9f 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,6 @@
 var fs = require('fs');
 
 var lib = require('./lib/presto-client');
-lib.version = JSON.parse(fs.readFileSync(__dirname + '/package.json')).version;
+lib.version = require('./package.json').version;
 
 exports.Client = lib.Client;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions