pulumi: yarn workspaces + nested pulumi project + local package reference = "Could not include required dependency"

Here’s a gutted project structure that matches what I’m trying to get working:

https://github.com/brandonbloom/pulumi-workspaces-repro

In short, there are three packages: “core”, “local”, and “cloud”. The bulk of the code is implemented in “core” and local development primarily operates via ts-node-dev running “local/index.ts”, which imports “core”. Then, there is a “cloud” package, which hosts the Pulumi bits, which also reuses core. Yarn creates a single top-level node_modules directory, and attempting to import core produces this error: Could not include required dependency 'example-core'

As a workaround, I’ve added an index.ts file that does require('./packages/cloud') in the root and moved the Pulumi *.yaml files to the root as well. Now pulumi up works if you omit -C packages/cloud, but I’d like to keep the Pulumi files contained to their package.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 20
  • Comments: 22 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I think you should just go to packages/cloud and run yarn add ... with all pulimi packages that you are going to use in that directory instead of just hoping that it will be requires from root

Looked into this a little today.

It appears the issue is that we use https://github.com/npm/read-package-tree to read the local package.json and recursively walk dependencies and their package.jsons to find the transitive dependencies of a package. However, read-pacakge-tree does not handle Yarn Workspaces. It assumes that wherever the package.json file is, the node_modules next to it will contain all of the child modules that are direct dependencies of that package.json.

https://github.com/npm/read-package-tree/blob/master/rpt.js#L109

We will likely either need to maintain a fork of read-package-tree that handles this case, or abandon read-package-tree and find a way to construct these dependencies more directly.

@vvo this only works for Yarn v1. This option is gone for Yarn v2.

Facing the same issue here in a yarn workspaces + lerna monorepo. I have a common package where I have shared code. I’m getting the same Could not include required dependency '@project/common' error. Is there plans to add support for this?

Following this as well, we’ve had in other solutions to really work hard to get around this. Having first class support for this would be a huge win over many other platform.

@DanNeish I’ve now switched my approach and am building out an NX plugin to make it easy to use Pulumi in an nx.dev mono repo.

I am now trying to create a small pulumi program for each service in the mono repo, then working towards being able to nx affected:up to deploy the appropriate stacks which have changes using NX’s impact analysis.

Has there been any movement on this issue?

As it stands it does not seem like pulumi works with yarn workspaces.