Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in combination with virtual module and missing package.json #1647

Open
dasdeo opened this issue Dec 14, 2023 · 0 comments · May be fixed by #1648
Open

Infinite loop in combination with virtual module and missing package.json #1647

dasdeo opened this issue Dec 14, 2023 · 0 comments · May be fixed by #1648

Comments

@dasdeo
Copy link

dasdeo commented Dec 14, 2023

  • Rollup Plugin Name: plugin-node-resolve
  • Rollup Plugin Version: 15.2.3
  • Rollup Version: 4.9.0
  • Operating System (or Browser): macOS Ventura 13.1
  • Node Version: v20.10.0
  • Link to reproduction (⚠️ read below): https://github.com/dasdeo/rollup-resolve-node-bug

Expected Behavior

Bundling should work the same regardless from where the bundler was invoked.

Actual Behavior

If the plugin fails to find a corresponding package.json it will hang forever.

Note that this is not remedied by setting rootDir.

Additional Information

I already tracked down the offending function, it is:

async function findPackageJson(base, moduleDirs) {
    const { root } = path.parse(base);
    let current = base;
    while (current !== root && !isModuleDir(current, moduleDirs)) {
        const pkgJsonPath = path.join(current, 'package.json');
        if (await fileExists(pkgJsonPath)) {
            const pkgJsonString = fs.readFileSync(pkgJsonPath, 'utf-8');
            return { pkgJson: JSON.parse(pkgJsonString), pkgPath: current, pkgJsonPath };
        }
        current = path.resolve(current, '..');
    }
    return null;
}

Variable current over time:

findPackageJson my-virtual-module
findPackageJson /Users/dasdeo/Desktop/rollup-bug-repo
findPackageJson /Users/dasdeo/Desktop
findPackageJson /Users/dasdeo
findPackageJson /Users
findPackageJson /
findPackageJson /
findPackageJson /
...
@dasdeo dasdeo linked a pull request Dec 14, 2023 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant