Remove automatic `projectName` / `projectVersion` inference
sindresorhus opened this issue · 2 comments
Lines 29 to 36 in 8329e55
It won't work for ESM.
The problem is that it's inconvenient for every user to have to find the path to their package.json, load the JSON, parse it, and then get those properties out of it themselves. Maybe we could add a new option called importMeta
at the same time. It could accept import.meta
. We could then use import.meta.url
to find the package.json. I'm open to other ideas.
Not sure if this overlaps with this issue or if this is a separate one. I'm using ES Modules for a CLI App. When I try to run the CLI command in the App directory or any child directory, it works. However, when I use yarn link
and then try to run it in a different directory including the parent directory, some command that uses Conf fails with the following error:
(node:7870) UnhandledPromiseRejectionWarning: Error: Project name could not be inferred. Please specify the `projectName` option.
at new Conf (/home/shreshtab/Documents/github/cli-apps/weather-cli-app/node_modules/conf/dist/source/index.js:90:23)
at configure (file:///home/shreshtab/Documents/github/cli-apps/weather-cli-app/src/configure.js:9:18)
at cli (file:///home/shreshtab/Documents/github/cli-apps/weather-cli-app/src/cli.js:67:7)
at file:///home/shreshtab/Documents/github/cli-apps/weather-cli-app/index.js:5:1
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7870) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7870) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
However, one workaround I found was to provide the projectName as an input per the example below and I was able to get my CLI App to work in any directory.
const config = new Conf({ projectName: 'weather-cli-app' });
For more information, I am using Conf v10.1.1 and Node v14.18.x, though I observed the same issue in other versions of Node as well.