Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today, when I re-installed packages in my project, I encountered a problem in your latest version v4.24.0.
The problem is that the function findConfig cannot find the function this.findConfigFile and throws an error.
Here is the very basic diff, that solved the problem for me for now (I moved the findConfigFile definition outside the module.exports).
diff --git a/node_modules/browserslist/node.js b/node_modules/browserslist/node.js
index 4a9f640..769d77b 100644
--- a/node_modules/browserslist/node.js
+++ b/node_modules/browserslist/node.js
@@ -185,6 +185,48 @@ function normalizeUsageData(usageData, data) {
}
}
+function findConfigFile(from) {
+ var resolved = eachParent(from, function (dir) {
+ var config = path.join(dir, 'browserslist')
+ var pkg = path.join(dir, 'package.json')
+ var rc = path.join(dir, '.browserslistrc')
+
+ var pkgBrowserslist
+ if (isFile(pkg)) {
+ try {
+ pkgBrowserslist = parsePackage(pkg)
+ } catch (e) {
+ if (e.name === 'BrowserslistError') throw e
+ console.warn(
+ '[Browserslist] Could not parse ' + pkg + '. Ignoring it.'
+ )
+ }
+ }
+
+ if (isFile(config) && pkgBrowserslist) {
+ throw new BrowserslistError(
+ dir + ' contains both browserslist and package.json with browsers'
+ )
+ } else if (isFile(rc) && pkgBrowserslist) {
+ throw new BrowserslistError(
+ dir + ' contains both .browserslistrc and package.json with browsers'
+ )
+ } else if (isFile(config) && isFile(rc)) {
+ throw new BrowserslistError(
+ dir + ' contains both .browserslistrc and browserslist'
+ )
+ } else if (isFile(config)) {
+ return config
+ } else if (isFile(rc)) {
+ return rc
+ } else if (pkgBrowserslist) {
+ return pkg
+ }
+ })
+
+ return resolved
+}
+
module.exports = {
loadQueries: function loadQueries(ctx, name) {
if (!ctx.dangerousExtend && !process.env.BROWSERSLIST_DANGEROUS_EXTEND) {
@@ -334,47 +376,7 @@ module.exports = {
return module.exports.parseConfig(fs.readFileSync(file))
},
- findConfigFile: function findConfigFile(from) {
- var resolved = eachParent(from, function (dir) {
- var config = path.join(dir, 'browserslist')
- var pkg = path.join(dir, 'package.json')
- var rc = path.join(dir, '.browserslistrc')
-
- var pkgBrowserslist
- if (isFile(pkg)) {
- try {
- pkgBrowserslist = parsePackage(pkg)
- } catch (e) {
- if (e.name === 'BrowserslistError') throw e
- console.warn(
- '[Browserslist] Could not parse ' + pkg + '. Ignoring it.'
- )
- }
- }
-
- if (isFile(config) && pkgBrowserslist) {
- throw new BrowserslistError(
- dir + ' contains both browserslist and package.json with browsers'
- )
- } else if (isFile(rc) && pkgBrowserslist) {
- throw new BrowserslistError(
- dir + ' contains both .browserslistrc and package.json with browsers'
- )
- } else if (isFile(config) && isFile(rc)) {
- throw new BrowserslistError(
- dir + ' contains both .browserslistrc and browserslist'
- )
- } else if (isFile(config)) {
- return config
- } else if (isFile(rc)) {
- return rc
- } else if (pkgBrowserslist) {
- return pkg
- }
- })
-
- return resolved
- },
+ findConfigFile,
findConfig: function findConfig(from) {
from = path.resolve(from)
@@ -385,7 +387,7 @@ module.exports = {
}
var resolved
- var configFile = this.findConfigFile(from)
+ var configFile = findConfigFile(from)
if (configFile) {
resolved = parsePackageOrReadConfig(configFile)
}
This issue body was partially generated by patch-package.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today, when I re-installed packages in my project, I encountered a problem in your latest version v4.24.0.
The problem is that the function
findConfigcannot find the functionthis.findConfigFileand throws an error.Here is the very basic diff, that solved the problem for me for now (I moved the
findConfigFiledefinition outside themodule.exports).This issue body was partially generated by patch-package.