philolegein
philolegein

Reputation: 1525

globals package "hoisted" but not linked in pnpm?

I have a pnpm monorepo (multiple workspaces). In one of the workspaces, I need to use the globals package, so that ESLint 9 can be made aware of native Node globals (e.g., process). What I end up with is:

/
/eslint.config.mjs // import globals from 'globals'
/node_modules
/node_modules/.pnpm/<most actual modules?>
/node_modules/<sym-links to most eslint modules but not to `globals`>
/package1/node_modules/<sym-link to globals>

I'm not sure what rules pnpm is using for where it creates sym-links, but the lack of the link in the top-level node_modules folder means ESLint can't find it and throws when it runs.

I tried adding a dev dependency for globals in package2 (even though it doesn't need it), thinking maybe that's what would trigger pnpm's top-level sim-linking, but it did not do so.

I can keep working by manually creating the link, but that's obviously not right. What's the right way to be using globals for some packages in a pnpm monorepo?

Upvotes: 0

Views: 261

Answers (1)

philolegein
philolegein

Reputation: 1525

Which packages are linked in the root modules directory is controlled by public-hoist-pattern in the .npmrc file. The ESLint files are linked because the default for this is ['*eslint*', '*prettier*']. To add globals (or anything else), you need to extend (or create) your .npmrc file:

# File: .npmrc
public-hoist-pattern[]='*eslint*'
public-hoist-pattern[]='*prettier*'
public-hoist-pattern[]='*globals*'

Upvotes: 1

Related Questions