question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

yarn workspaces: packages found in node_modules are not excluded when using list/fix-mismatches

See original GitHub issue

Description

Hi, We’re using Yarn Workspaces with the glob pattern packages/**, since we have a deep package tree. Some of the packages have their own node_modules folder with packages inside. Yarn is ok with it and automatically doesn’t search for packages in node_modules.

However, syncpack has its own resolving mechanism and does include packages from node_modules.

Suggested Solution

Automatically exclude node_modules when searching for packages.

Is there a way maybe for a user to exclude it via config? I couldn’t find one.

Thanks!!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
tom-fletchercommented, Mar 24, 2022

I ran into the same issue with pnpm as my pnpm-workspace.yaml has similar glob patterns such as:

packages:
  - 'apps/**'

As a workaround, you can create a .syncpackrc.js in your project root and perform your own package.json resolution.

For pnpm:

const fs = require('fs')
const glob = require('glob')
const yaml = require('yaml')

let source = ['package.json'] // Include the root package.json

const pnpmWorkspaceFile = fs.readFileSync('pnpm-workspace.yaml', 'utf8')
const workspaces = yaml.parse(pnpmWorkspaceFile)

workspaces.packages.map((workspacePackage) => {
	source = source.concat(
		glob.sync(`${workspacePackage}/package.json`, {
			ignore: `**/node_modules/**`,
		})
	)
})

module.exports = {
	source,
}

And similar for yarn:

const glob = require('glob')

let source = ['package.json'] // Include the root package.json

const packageJson = require('./package.json')
const workspaces = packageJson.workspaces

workspaces.map((workspacePackage) => {
	source = source.concat(
		glob.sync(`${workspacePackage}/package.json`, {
			ignore: `**/node_modules/**`,
		})
	)
})

module.exports = {
	source,
}

However, it would be much nicer if node_modules were always automatically excluded so I will also submit a PR for this.

1reaction
JamieMasoncommented, Apr 12, 2022

Released in 6.2.1, thanks a lot @tom-fletcher

Read more comments on GitHub >

github_iconTop Results From Across the Web

Yarn workspaces: a lot of `node_modules` are missing in ...
When I use yarn install and I go to the frontend/node_modules I see just several modules, but not all needed which are in...
Read more >
typescript doesn't exclude node_modules while compile
typescript doesn't exclude node_modules while compile ... to tell I'm using yarn workspace and I'm excluding node_modules in all tsconfig.
Read more >
Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >
Bug listing with status UNCONFIRMED as at 2022/12/24 17 ...
Bug:128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils not sys-apps/net-tools" status:UNCONFIRMED resolution: severity:enhancement ...
Read more >
SUSE-SU-2020:2876-1: critical: Security update for ardana ...
(#22859) * Backend plugins: Exclude plugin metrics in Grafana's metrics ... yields no result (#22695) * Dependency: sdk's dataframe package ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found