Skip to content

Commit 5a4a0c4

Browse files
authored
Fix dynamic package.json resolving from unpkg (codesandbox#490)
1 parent a6dc3d1 commit 5a4a0c4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/app/src/sandbox/eval/npm/fetch-npm-module.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ function downloadDependency(depName: string, depVersion: string, path: string) {
9797
return packages[path];
9898
}
9999

100+
const requestedPaths = [];
101+
100102
function resolvePath(
101103
path: string,
102104
currentPath: string,
@@ -129,17 +131,17 @@ function resolvePath(
129131
const depPath = p.replace('/node_modules/', '');
130132
const depName = getDependencyName(depPath);
131133

132-
// We don't try to download package.json, because we can assume that
133-
// all package.json files have been included in the bundle sent by
134-
// the packager.
135-
if (depPath.endsWith('package.json')) {
134+
// To prevent infinite loops we keep track of which dependencies have been requested before.
135+
if (requestedPaths.includes(depPath)) {
136136
const err = new Error('Could not find ' + p);
137137
err.code = 'ENOENT';
138138

139139
callback(err);
140140
return null;
141141
}
142142

143+
requestedPaths.push(depPath);
144+
143145
// eslint-disable-next-line
144146
const subDepVersionVersionInfo = await findDependencyVersion(
145147
currentPath,

0 commit comments

Comments
 (0)