diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb index aee6883934c..dbfb183df0c 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb @@ -380,9 +380,10 @@ def clean_npmrc_in_path(yarn_lock) dirs.pop while dirs.any? npmrc = dirs.join("/") + "/.npmrc" - break unless File.exist?(npmrc) - - File.write(npmrc, File.read(npmrc).gsub(/\$\{.*\}/, "")) + if File.exist?(npmrc) + # If the .npmrc file exists, clean it + File.write(npmrc, File.read(npmrc).gsub(/\$\{.*?\}/, "")) + end dirs.pop end end