Skip to content

postinstall assumes package.json exists even if MAXMIND_LICENSE_KEY is set #37

@rkaw92

Description

@rkaw92

Hi,
I've hit a really weird corner case when node-geolite2 is used with Meteor.js. Meteor requires users to perform a post-build step in the application bundle directory - here's a snippet from the README file it creates:

$ (cd programs/server && npm install) 

This, in turn, launches npm-rebuild.js, which goes into several sub-directories (notably npm/) and does npm install in them. This is all quite complex, but the end result is: it launches npm install, in a directory (cwd) which has no package.json file. This throws, even though the MAXMIND_LICENSE_KEY environment variable is set:

Error: Cannot find module '<some_meteor_bundle_dir>/programs/server/npm/package.json' Require stack: - <some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/utils.js - <some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/scripts/postinstall.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.Module._load (internal/modules/cjs/loader.js:667:27) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at getConfig (<some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/utils.js:9:23) at getSelectedDbs (<some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/utils.js:31:18) at Object.<anonymous> (<some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/scripts/postinstall.js:38:18) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) { code: 'MODULE_NOT_FOUND', requireStack: [ '<some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/utils.js', '<some_meteor_bundle_dir>/programs/server/npm/node_modules/geolite2/scripts/postinstall.js' ] } 

As far as I can tell, prior to PR #34, this library had a list of configuration loaders which would run one-by-one, so if the env variable was enough, we never tried to require() the package.json file. However, #34 broke this - now, the postinstall script blindly tries to find the file, and fails - since the file does not exist in the current working directory.

This results in post-build failures of Meteor application bundles for applications that have geolite2 as a dependency. The current work-around seems to be setting METEOR_SKIP_NPM_REBUILD=1 (which limits deployment options, really). The problem's scope is not limited to Meteor - anything that tries to do an npm install in a CWD without a package.json will fail in the same way.

A solution could be to gracefully recover from a missing config and assume some defaults w.r.t. which databases the user wants. This would restore the previous behavior (pre #34), where MAXMIND_LICENSE_KEY was enough to use this package.

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