0

I'm setting up a package to pull settings from the package.json of the application using the package. I'm currently doing that with this code:

var path = require('path');
var packageSettings = require(path.resolve('package.json'));
export default packageSettings.myPackage || {};

However, node/webpack throws this warning: Critical dependency: the request of a dependency is an expression

I tried searching for a way to do this and had no luck. The documentation on config makes it sound like that applies only to scripts. Is this the best way to do this, or is there another?

Jay Bienvenu
  • 3,069
  • 5
  • 33
  • 44
  • `require('./package.json')` – Roland Starke Aug 20 '19 at 14:21
  • And that's going to refer to package.json in the application using the package, not the package itself? – Jay Bienvenu Aug 20 '19 at 14:23
  • Yeah (if I understood the question), it will resolve the relative path with `__dirname`. – Roland Starke Aug 20 '19 at 14:26
  • OK, but I want to put this code in my package so that I can inject configuration into the package. I want to get my package's settings from the application that uses it, or the global state if necessary. – Jay Bienvenu Aug 20 '19 at 14:40
  • Ah got it. No I don't know a way then. Maybe: https://stackoverflow.com/a/26163910/5378743 (But in the express boilerplate code for example, the entry point is not in the root folder, so not a robust solution) – Roland Starke Aug 20 '19 at 14:50

0 Answers0