Repository: parcel-bundler/parcel
File: packages/utils/node-resolver-core/src/NodeResolver.js (JavaScript)

Code before:
        // Preserve the `node:` prefix for use later.
        // Node does not URL decode or support query params here.
        // See https://github.com/nodejs/node/issues/39710.
        return {
          filePath: filename,
        };
      } else if (url.protocol === 'file:') {
        // $FlowFixMe
        filePath = fileURLToPath(url);
      } else if (specifierType === 'url') {
        // Don't handle other protocols like http:
        return null;
      } else {
        // Throw on unsupported url schemes in ESM dependencies.
        // We may support http: or data: urls eventually.
        throw new ThrowableDiagnostic({
          diagnostic: {
            message: `Unknown url scheme or pipeline '${url.protocol}'`,
          },
        });
      }

      return {
        filePath,
        query: url.search
          ? Object.fromEntries(new URLSearchParams(url.search.slice(1)))
          : undefined,
      };
    } else {
      // CommonJS specifier. Query params are not supported.
      return {
        filePath: path.resolve(dir, filename),
      };
    }
  }

  async loadRelative(
    filename: string,
    extensions: Array<string>,
    env: Environment,
    parentdir: string,
    ctx: ResolverContext,
  ): Promise<?ResolvedFile> {
    // Find a package.json file in the current package.
    let pkg = await this.findPackage(filename, ctx);

    // First try as a file, then as a directory.
    let resolvedFile = await this.loadAsFile({
      file: filename,
      extensions,
      env,

Review comment (bug):
Is it a problem that this doesn't handle duplicates the same way?

```
> require('querystring').parse('a=b&a=c')
[Object: null prototype] { a: [ 'b', 'c' ] }

> Object.fromEntries(new URLSearchParams('a=b&a=c'))
{ a: 'c' }
```

Code after:
        // See https://github.com/nodejs/node/issues/39710.
        return {
          filePath: filename,
        };
      } else if (url.protocol === 'file:') {
        // $FlowFixMe
        filePath = fileURLToPath(url);
      } else if (specifierType === 'url') {
        // Don't handle other protocols like http:
        return null;
      } else {
        // Throw on unsupported url schemes in ESM dependencies.
        // We may support http: or data: urls eventually.
        throw new ThrowableDiagnostic({
          diagnostic: {
            message: `Unknown url scheme or pipeline '${url.protocol}'`,
          },
        });
      }

      return {
        filePath,
        query: url.search ? new URLSearchParams(url.search) : undefined,
      };
    } else {
      // CommonJS specifier. Query params are not supported.
      return {
        filePath: path.resolve(dir, filename),
      };
    }
  }

  async loadRelative(
    filename: string,
    extensions: Array<string>,
    env: Environment,
    parentdir: string,
    ctx: ResolverContext,
  ): Promise<?ResolvedFile> {
    // Find a package.json file in the current package.
    let pkg = await this.findPackage(filename, ctx);

    // First try as a file, then as a directory.
    let resolvedFile = await this.loadAsFile({
      file: filename,
      extensions,
      env,
      pkg,
      ctx,
    });