parcel icon indicating copy to clipboard operation
parcel copied to clipboard

NodePackageManager doesn't cache this.resolver when running multiple builds from same directory

Open wardpeet opened this issue 2 years ago β€’ 0 comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @parcel/[email protected] for the project I'm working on.

When running multiple parcel builds from the same directory but with different entry files I get the following error:

{
  "name": "BuildError",
  "diagnostics": [
    {
      "origin": "Error",
      "message": "Cannot read properties of undefined (reading 'getInvalidations')",
      "name": "TypeError",
      "stack": "TypeError: Cannot read properties of undefined (reading 'getInvalidations')\n    at NodePackageManager.getInvalidations (<project>\\node_modules\\@parcel\\package-manager\\lib\\index.js:3794:51)\n    at createDevDependency (<project>\\node_modules\\@parcel\\core\\lib\\requests\\DevDepRequest.js:51:46)\n    at async ResolverRunner.resolve (<project>\\node_modules\\@parcel\\core\\lib\\requests\\PathRequest.js:322:29)\n    at async Object.run (<project>\\node_modules\\@parcel\\core\\lib\\requests\\PathRequest.js:92:16)\n    at async RequestTracker.runRequest (<project>\\node_modules\\@parcel\\core\\lib\\RequestTracker.js:634:20)\n    at async AssetGraphBuilder.runPathRequest (<project>\\node_modules\\@parcel\\core\\lib\\requests\\AssetGraphRequest.js:339:18)\n    at async $31bd78e367586e0a$export$2e2bcd8739ae039._runFn (<project>\\node_modules\\@parcel\\utils\\lib\\index.js:34294:13)\n    at async $31bd78e367586e0a$export$2e2bcd8739ae039._next (<project>\\node_modules\\@parcel\\utils\\lib\\index.js:34287:9)"
    }
  ]
}

The NodePackageManager caches the files but do not initiate a resolver which lead the the above issue.

for (const file of preprocessFiles) {
	console.log(`   Building  ${file}`);
	const bundler = new Parcel({
		entries: file,
		defaultConfig: './.parcelrc.preprocess',
		mode: isWatch ? 'development' : 'production',
		shouldAutoInstall: true,
		targets: ['preprocess'],
		shouldDisableCache: true,
	});

	if (isWatch) {
		watch(bundler, file);
	} else {
		await build(bundler);
	}
}

Here is the diff that solved my problem:

diff --git a/node_modules/@parcel/package-manager/lib/index.js b/node_modules/@parcel/package-manager/lib/index.js
index 82e695f..b2b09e6 100644
--- a/node_modules/@parcel/package-manager/lib/index.js
+++ b/node_modules/@parcel/package-manager/lib/index.js
@@ -3611,7 +3611,12 @@ class NodePackageManager {
         let basedir = (0, ($parcel$interopDefault($5VgCY$path))).dirname(from);
         let key = basedir + ":" + id;
         let resolved = cache.get(key);
-        if (!resolved) {
+
+        if (resolved) {
+					if (this.resolver == null) {
+						this.resolver = this._createResolver();
+					}
+				} else {
             let [name] = (0, $5VgCY$parcelutils.getModuleParts)(id);
             try {
                 resolved = this.resolveInternal(id, from);

This issue body was partially generated by patch-package.

wardpeet avatar Nov 27 '23 21:11 wardpeet