Skip to content

Support for Yarn portal dependencies #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rayshan opened this issue Jan 12, 2021 · 8 comments
Closed

Support for Yarn portal dependencies #82

rayshan opened this issue Jan 12, 2021 · 8 comments
Assignees
Labels
priority: low status: awaiting user response type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@rayshan
Copy link

rayshan commented Jan 12, 2021

Hi! I think the logic that detects whether next.js is installed should go through all the package.json's in a monorepo's packages.

For my project here, I'm using yarn v2 berry pnp to manage a monorepo. There are 2 packages:

  • packages/common, containing shared components.
  • packages/web, the app to build, depends on next.js and the above package via "@finance-apps/common": "portal:../common".

Here are my build settings:

Screen Shot 2021-01-12 at 12 01 09 PM

This doesn't work because the root package.json doesn't depend on next.js. Changing the base directory in Netlify to packages/web doesn't work because we need yarn 1 to install yarn 2, and yarn 1 doesn't recognize portal dependencies.

@ehmicky
Copy link

ehmicky commented Jan 13, 2021

Hi @rayshan,

Thanks for sharing this.

The core problem here is that we currently don't support Yarn-specific portal:... links in package.json.

A workaround in your case could be to yarn install next in packages/web/package.json. Since it's already one of your dependencies, this should not change anything except it would make Netlify's detection of Next.js work.
Would this workaround work for you?

@rayshan
Copy link
Author

rayshan commented Jan 13, 2021

Thanks @ehmicky. next is already a dependency for the web package. It's not a dependency for the whole project though (i.e. not in the root package.json). Maybe that's what your build system or this plugin is looking for?

@ehmicky
Copy link

ehmicky commented Jan 13, 2021

The plugin is using find-up from either the repository root directory or (if any) the base directory.
For monorepos, we recommend setting the base directory (link to documentation). This should solve your problem.

@rayshan
Copy link
Author

rayshan commented Jan 13, 2021

I did:

Changing the base directory in Netlify to packages/web doesn't work because we need yarn 1 to install yarn 2, and yarn 1 doesn't recognize portal dependencies.

So you're right about the root cause being portal dependencies.

@ehmicky ehmicky changed the title Monorepo build: Error: This site does not seem to be using Next.js. No support for Yarn portal dependencies Jan 15, 2021
@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jan 15, 2021
@ehmicky ehmicky changed the title No support for Yarn portal dependencies Support for Yarn portal dependencies Jan 15, 2021
@ehmicky
Copy link

ehmicky commented Jan 15, 2021

we need yarn 1 to install yarn 2

Looking at Yarn migration guide, it seems like this is the reason why you need this setup, correct?

Would adding next to the top-level package.json be an option?

@lukeocodes
Copy link

@rayshan did changing the base directory and having next installed as a regular dependency in the web/package.json resolve this for you?

@ericapisani ericapisani self-assigned this Apr 12, 2022
@ericapisani
Copy link

Hi @rayshan ,

I created a test monorepo with the following structure to try and mirror what you mentioned above:

package2
|--> package.json
|--> add.js 

packageWithNextJS
|--> package.json  // References package2 as a portal dependency (i.e: "package2": "portal:../package2")
|--> pages
  |--> index.js  // Imports add.js from package2, invokes the function, and displays the result

package.json // contains no dependencies
yarn.lock

By setting the NETLIFY_USE_YARN environment variable to true within your sites' 'build & deploy' settings, you can get the Netlify builds to use yarn rather than npm, and not rely on Netlify's default behaviour of automatically using yarn when it detects a yarn.lock file in the base directory.

From the tests I was running, I suspect that because you had needed to specify that packages/web as your base directory as you mentioned above, the yarn.lock file may not have existed within that directory (in my test monorepo it existed on the root directory) and so Netlify attempts to use npm rather than yarn resulting in an error that looks something like:

Unsupported URL Type "portal:": portal:../package2

which is why setting the NETLIFY_USE_YARN appears to be needed.

If for some reason that still doesn't resolve your issue (perhaps because the yarn version installed tends to be v1 by default though my tests are showing that the portal dependency is correctly resolving with this environment variable alone), you can also set the yarn version explicitly by setting a YARN_VERSION environment variable to any released version above v2 (I used v3.2.0 to test).

I hope this helps!

@ericapisani
Copy link

Since it's been a couple of weeks since my previous message, I'm going to close this issue due to inactivity. If you continue to run into issues and my notes above didn't help resolve them, feel free to reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low status: awaiting user response type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

5 participants