webpack / webpack/enhanced-resolve

Bug: resolves using node_modules when using PnP

Open
#273 12 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
983
Forks
206
Avg merge
23h 27m
Merged PRs (30d)
15

Description

Describe the bug

When running under Yarn PnP enhanced-resolve will still use the node_modules resolution

To Reproduce

Setup:

mkdir repro && cd repro
yarn init -y
yarn set version berry
yarn add enhanced-resolve@5.4.1 lodash@4.17.20

Code:

import { ResolverFactory, CachedInputFileSystem } from 'enhanced-resolve';
import path from 'path';
import fs from 'fs';

const cachedFS = new CachedInputFileSystem(fs);

const commonResolver = ResolverFactory.createResolver({
  fileSystem: cachedFS,
  useSyncFileSystemCalls: true,
});

fs.mkdirSync(path.join(__dirname, 'node_modules/lodash'), { recursive: true });
fs.writeFileSync(path.join(__dirname, 'node_modules/lodash/foo.js'), '');

commonResolver.resolveSync({}, __filename, 'lodash/foo');
throw new Error(`Resolve should have failed since lodash/foo doesn't exist`);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Yarn Berry setup and inspect the ResolverFactory.createResolver and resolveSync entry points. Trace why the resolver accepts the created node_modules/lodash/foo.js under Yarn PnP. Done means the same resolveSync call fails when lodash/foo is unavailable through PnP, despite that node_modules path existing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.