-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Description
In NPM packages such as @types/node
and @types/semver
etc, the "main" property in package.json is an empty string "".
So when require.resolve() is called on those:
require.resolve('@types/node')
require.resolve('@types/semver')
errors are thrown because the main property is empty..
so I am looking for a way to resolve the package location even if the main property is empty or missing..my suggestion would be to just return the location of package.json, something like:
require.resolve('@types/semver', {ifMainEmpty:""})
I am not sure if the suggestion in the title is a good idea, but I am looking to find the location of package.json so I can read other properties from it.
One sane default - if the main property is missing or empty, then it should default to index.js?
Right now if it's missing, it should be something like:
index.js
package.json (missing main property)
and the path to index.js is now the require.resolve return value. So what about:
index.js
package.json (main property = "")
Right now the situation seems like a hack (using main: "")