Skip to content
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

CI failing with "We've detected multiple sites inside your repository" #5977

Closed
scottlovegrove opened this issue Sep 2, 2023 · 12 comments · Fixed by #6362 or #6539
Closed

CI failing with "We've detected multiple sites inside your repository" #5977

scottlovegrove opened this issue Sep 2, 2023 · 12 comments · Fixed by #6362 or #6539
Labels
area: monorepo type: bug code to address defects in shipped code

Comments

@scottlovegrove
Copy link

Describe the bug

I have a CI deployment that has been working fine until it started using v16 of the CLI.

The command I have within my deployment script looks like this

npx netlify-cli deploy --prod --dir=./webclient/dist

But when that command now runs, and pulls down v16, the deployment fails with

We've detected multiple sites inside your repository
? Select the site you want to work with (Use arrow keys or type to search)
❯ @shiftsync/apiclient  apiclient  --filter @shiftsync/apiclient 
  @shiftsync/core  core  --filter @shiftsync/core 
Error: Process completed with exit code 130.

I specified the version to be 15 and deployment ran through ok, letting it pull 16 again results in the same error, every time.

My repo has the following structure:
image

The command is run from the root of the repo, passing in the webclient/dist folder once the build has finished earlier in the CI process.

Steps to reproduce

I'm unsure how to repro this outside of a CI environment. If I try and run the same command locally, after building the web app, the cli client ends up publishing a blank site.

Configuration

No response

Environment

System:
OS: Linux 5.15 Ubuntu 20.04 LTS (Focal Fossa)
CPU: (2) x64 Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz
Memory: 22.16 GB / 31.35 GB
Container: Yes
Shell: 5.0.16 - /bin/bash
Binaries:
Node: 18.16.0 - ~/.local/state/fnm_multishells/22934_1693641170757/bin/node
npm: 9.5.1 - ~/.local/state/fnm_multishells/22934_1693641170757/bin/npm
npmGlobalPackages:
netlify-cli: 15.8.1

@chinanderm
Copy link

Noticing this too on v16. Downgraded and pinned to v15.11.0 to get our CI/CD pipeline for deployments working again.

@South-Paw
Copy link

South-Paw commented Sep 13, 2023

Also just hit this while debugging failing builds in a monorepo.

The Netlify CLI's deploy filter shouldn't need to be set when an explicit dir flag has been passed IMO

@lukasholzer
Copy link
Collaborator

Hey, @scottlovegrove, thanks for reaching out.

First of all, multiple things are happening here; let me maybe explain to you:

We've released a new major (breaking) version that added better monorepo support. We rely on Semantic Versioning, where a new major version indicates that this contains breaking changes and might break existing workflows.

here are the docs for it: https://docs.netlify.com/cli/get-started/#work-with-monorepos
and here is the changelog post: https://www.netlify.com/blog/better-monorepos-on-netlify/

Sadly, we could not introduce this new feature without breaking existing workflows.
The significant change is that if you run from the root of a monorepo, we need to know which part you want to work on. A command is always tied to serve one app or deploy one app so we need to know which app is that -> therefore you can see the prompt. This is mainly required for new ways to store and read up configuration files (see docs).

You can bypass this prompt by changing to this directory before or using the --filter flag in CI/CD environments.

@South-Paw the reason on why the CLI deploy cannot omit the --filter flag when an explicit dir is specified is that a dir does not match a site. We are still missing which configuration file to pick up or about the siteId, which is stored in the .netlify/state.json. As a monorepo can have 1 to n sites stored in it we cannot have this information stored on the repository root.

A good example where the publish directory differs from the package location is Nx (a popular monorepository build system). There the publish directory would be dist/apps/app-1 and the configuration files would be stored at: apps/app-1/{netlify.toml,|netlify/state.json}

/
├─ apps/
│  ├─ app-1/
│  │  ├─ .netlify/state.json
│  │  ├─ package.json
│  │  ├─ netlify.toml
│  │  ├─ ...app-1-source-files
│  ├─ app-2/
│  │  ├─ .netlify/state.json
│  │  ├─ package.json
│  │  ├─ netlify.toml
│  │  ├─ ...app-2-source-files
│
├─ other-packages/
│  ├─ component-library/
│  │  ├─ package.json
│  │  ├─ ...component-library-source-files
│
├─ package.json

@scottlovegrove I hope this helps troubleshoot this issue for you. If there is still an issue or something does not work I'm more than happy to help you get it sorted out if you provide more information (framework, folder tree, etc.) or maybe a simple reproducible example.

@South-Paw
Copy link

South-Paw commented Sep 18, 2023

@lukasholzer 👋

Our monorepo doesn't actually use .netlify/state.json files in any projects, we just pass the env variable NETLIFY_SITE_ID with the deploy command in GitHub action workflows.

We don't use NX, just npm workspaces and dist folders end up inside the app directories - not the root. I've also raised #6000 as somewhere along the line the CLI now manages to deploy our entire project to the Netlify site rather than the specified dir... which was fantastic to discover.

It just seems like Netlify CLI is making a lot of assumptions about project toolchain and setups that are then being built into the CLI commands (e.g. filter and now the deploy cwds) that limit the CLIs usefulness and flexibility. I appreciate developing/supporting every use case is tricky - but debugging some of this recent stuff has made for a very frustrating day.

@lukasholzer
Copy link
Collaborator

Sorry for the frustration @South-Paw.

Regarding the .netlify folder, this is something internal netlify is creating and relying on for storing internal state and build outputs like bundled functions etc.

Now if you have multiple applications, we cannot store them in the root as this would collide.
If you don't need those things, then it's one point, but others might do. I was not thinking that you use Nx just wanted to point out that it is not that easy to omit the --filter flag when a dir is provided as it might fit your use case, but we have to consider way more ways to develop in a monorepo.

If you could maybe tell us some of the hiccups and things that frustrated you on debugging this, this would be so helpful so we can try to make it more obvious and better in the future.

There will be always bugs, so anything we can do to make troubleshooting/issue creation easier is something I would love to do!

@jgeringer
Copy link

Hi @lukasholzer ,

We are experiencing a similar issue after upgrading netlify-cli from 15.11.0 to 16.4.2. We too are now getting the "We've detected multiple sites inside your repository" message when running netlify dev. Note that we do use npm workspaces and have two package.json files: One at the root of the repo, and one in a subfolder of root. The problem is that when running netlify dev, the "We've detected multiple sites inside your repository" list prompt only displays one site (the one in the subfolder) and not the one on the root level. Do you know if there is a way to have it pickup the root level?

Note: We've tried netlify dev --filter [root package.json name property value] but it still prompts us to only select the one in the subfolder.

Thanks!

@lukasholzer
Copy link
Collaborator

@jgeringer I would love to understand your use case more on having a workspace, but it seems that the root is a package as well?

So while implementing the workspace feature, we've tried to stick to the implementation logic of pnpm workspaces, yarn workspaces and npm workspaces where the goal is to have everything in sub packages distributed to the workspace.

There is indeed a way how to bypass the --filter flag and fall back to the old behavior by providing the --cwd . flag (when running from the root).

In this case, you tell the CLI that you know where the current working directory is, and we don't have to perform heuristics about where we can detect it in a workspace.

Nevertheless, I would love to understand your use case or maybe you can share some details about your workspace structure!

@jgeringer
Copy link

Hi @lukasholzer , thanks for the quick reply!
Yes, that's correct, in our case, the root is a package as well. Great to know about the --cwd flag, haven't seen that one in the cli docs. Is that page, and the getting started page, the most up to date place to find info about the Netlify CLI?

In our case, we would like to be able to run a script in one of the packages in a sub directory first, and then when that is done, run a script in the root package. If they were broken out into sibling directories, they wouldn't be able to communicate in that order. Sounds like we would have to re-work our directory structure later on or use the --cwd flag. Thank you!

@jzempel
Copy link

jzempel commented Nov 20, 2023

@lukasholzer rather than relying on an undocumented --cwd flag, would it be better if netlify-cli were updated to use something like is-interactive to determine whether or not to prompt the user for monorepo sites?

@ForbesLindesay
Copy link

This was incredibly frustrating. I just want to upload a directory as a netlify website. Everything's already built and in the correct folder.

I tried:

The magic incantation that finally worked (https://github.com/ForbesLindesay/atdatabases/actions/runs/7506096220/job/20436748850) is:

netlify deploy --cwd . --filter @databases/website --dir=packages/website/out

Could you maybe add a simple command for uploading/deploying a directory? If I wanted netlify to magically figure out how to install dependencies & build the site for me, I'd be using netlify's CI service. The whole reason I'm using the CLI is because I want to just upload an already built directory to an existing site.

@lukasholzer
Copy link
Collaborator

@ForbesLindesay for that there is the --cwd command this should not need the --filter.

So, in your case, netlify deploy --cwd packages/website/out should be enough.

I understand your request, but the CLI must work for complex scenarios where we detect a framework inside a monorepo, as well as a lot of customers facing this challenge. Using the CLI just to upload a directory is not really common.

@lukasholzer
Copy link
Collaborator

Instead of using the "non-public" --cwd flag you could just set the cwd of your github actions task or CI runnter to the cwd of the monorepo like apps/my-app this should work as well

zregvart added a commit to zregvart/cli that referenced this issue Apr 2, 2024
zregvart added a commit to zregvart/cli that referenced this issue Apr 18, 2024
zregvart added a commit to zregvart/cli that referenced this issue Apr 22, 2024
sarahetter added a commit that referenced this issue May 2, 2024
Fixes #5977

Co-authored-by: Sarah Etter <sarah.etter@netlify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: monorepo type: bug code to address defects in shipped code
Projects
None yet
8 participants