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

[turborepo] Yarn installing from npm registry rather than internal packages #6322

Closed
achadee opened this issue Oct 31, 2023 · 10 comments
Closed
Labels
area: docs Improvements or additions to documentation needs: author input owned-by: turborepo

Comments

@achadee
Copy link

achadee commented Oct 31, 2023

What version of Turborepo are you using?

1.10.16

What package manager are you using / does the bug impact?

Yarn v2/v3 (node_modules linker only)

What operating system are you using?

Mac

Describe the Bug

Hey guys, im following this tutorial to the tee
https://turbo.build/repo/docs/handbook/sharing-code/internal-packages

and yarn keeps trying to install this package:
https://www.npmjs.com/package/math-helpers

Any ideas whats happening?

Yarn v: 3.4.1
Node: 19.7.0
npm: 9.5.0

yarn lock

"math-helpers@npm:*":
  version: 0.1.0
  resolution: "math-helpers@npm:0.1.0"
  checksum: 9ce4bc05dc3b5268a73878f5d7afa83b5c17b6203f09200b3ffae459319c03f5e4772a6da7122a6a5319f3206d58dd607e617d2f19197894c28ef64ab773dfcd
  languageName: node
  linkType: hard

apps/web/packages.json

"dependencies": {
    ...
    "math-helpers": "*",
  }

Expected Behavior

yarn should install the local internal packages when passing the *

To Reproduce

Follow the tutorial above with the versions?

Reproduction Repo

No response

@achadee achadee added kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage owned-by: turborepo labels Oct 31, 2023
@chris-olszewski
Copy link
Contributor

If you want to depend on a workspace Yarn has the workspace: protocol which indicates you want to depend on an internal package instead of one from npm.

I see our docs don't include this for Yarn2+ and we should add it.

@chris-olszewski chris-olszewski added area: docs Improvements or additions to documentation and removed kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage labels Nov 1, 2023
@tknickman
Copy link
Member

@achadee can you share your full package.json here along with the directory structure of your monorepo? I just want to verify that you have yarn workspaces configured correctly.

@achadee
Copy link
Author

achadee commented Nov 6, 2023

Hey Sorry guys, been on 5 days of flights, I'll get back to you with some more of my config in a day or 2

@achadee
Copy link
Author

achadee commented Nov 7, 2023

apps/web/package.json

{
  "name": "next-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build"
  },
  "dependencies": {
    "@expo/next-adapter": "5.0.2",
    "app": "*",
    "math-helpers": "*",
    "next": "13.4.19",
    "raf": "^3.4.1",
    "setimmediate": "^1.0.5"
  },
  "devDependencies": {
    "@storybook/addon-essentials": "^7.5.1",
    "@storybook/addon-interactions": "^7.5.1",
    "@storybook/addon-links": "^7.5.1",
    "@storybook/addon-onboarding": "^1.0.8",
    "@storybook/blocks": "^7.5.1",
    "@storybook/nextjs": "^7.5.1",
    "@storybook/react": "^7.5.1",
    "@storybook/testing-library": "^0.2.2",
    "@types/node": "17.0.21",
    "autoprefixer": "^10.4.7",
    "eslint-config-next": "13.2.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "storybook": "^7.5.1",
    "tailwindcss": "^3.0.24"
  }
}

packages/math-helpers/package.json

{
  "name": "math-helpers",
  "main": "src/index.ts",
  "types": "src/index.ts",
  "dependencies": {
    "typescript": "latest"
  }
}

packages/math-helpers/src/index.ts

export const addCustom = (a: number, b: number) => {
  return a + b;
};
 
export const subtractCustom = (a: number, b: number) => {
  return a - b;
};

Yarn Install snippet:

➤ YN0000: ┌ Fetch step
➤ YN0013: │ math-helpers@npm:0.1.0 can't be found in the cache and will be fetched from the remote
➤ YN0000: └ Completed in 0s 245ms

Its worth noting that the template I started with, included a packages/app which resolves to app: "*" perfectly fine in apps/web
https://github.com/nandorojo/solito

When changing to workplace:* I get the following error:

math-helpers@workplace:* isn't supported by any available resolver

@tknickman
Copy link
Member

@achadee thanks for following up, could you share your root package.json as well?

@hamudeshahin
Copy link

@tknickman Hi!
I have a problem with yarn install command when I am trying to install all packages in root directory. The problem started when I change the name of my package from ui to geeks-ui.
Also I have already change the name of package in the package.json files in my apps directory.

The error which I am facing is:

error Couldn't find package "geeks-ui@*" required by "docs@0.1.0" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

What exactly is the problem here??

@achadee
Copy link
Author

achadee commented Nov 13, 2023

@tknickman

here you go:

/package.json

{
  "name": "skedyul",
  "private": true,
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  "devDependencies": {
    "@babel/plugin-syntax-import-meta": "^7.10.4",
    "@types/react": "^18.2.21",
    "@types/react-native": "^0.72.2",
    "babel-plugin-transform-import-meta": "^2.2.1",
    "dotenv-cli": "^7.3.0",
    "eslint": "^8.21.0",
    "prettier": "^3",
    "turbo": "^1.4.2",
    "typescript": "^5.2.2"
  },
  "scripts": {
    "native": "cd apps/native && yarn dev",
    "web": "cd apps/web && dotenv -e .env -- yarn next",
    "storybook": "cd apps/web && yarn storybook",
    "dev": "dotenv -- turbo dev"
  },
  "resolutions": {
    "metro": "~0.76.7",
    "metro-resolver": "~0.76.7"
  },
  "nohoist": [
    "**/expo-router",
    "**/expo-router/**"
  ],
  "packageManager": "yarn@3.4.1",
  "dependencies": {
    "@reduxjs/toolkit": "^1.9.7",
    "react-redux": "^8.1.3"
  }
}

@achadee
Copy link
Author

achadee commented Nov 23, 2023

@tknickman I was able to fix the issue by doing the following:

  • switching away from yarn to pnpm
  • making sure my package name wasnt generic so instead of db i called it my-app-name1234-db

I think its either worth updating the docs to reflect this, or fixing this bug, I wasted so much time on this.

@loctn
Copy link
Contributor

loctn commented Mar 5, 2024

A version needs to be added to the math-helpers package - updated docs to reflect here: #7626

chris-olszewski pushed a commit that referenced this issue Mar 5, 2024
### Description

Added the package version to the internal packages docs example. Without
version in the shared internal package, Yarn will attempt to fetch from
the npm registry leading to rabbitholes like this one:
#6322

### Testing Instructions

Confirm docs load with new text.
@chris-olszewski
Copy link
Contributor

Closing this as this is an issue with use of the underlying package managers. With #6696 we have callouts for use of workspace: protocol.

If you encounter an issue similar to this one and feel our docs could be made clearer, then please open a new issue along with which docs should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Improvements or additions to documentation needs: author input owned-by: turborepo
Projects
None yet
Development

No branches or pull requests

5 participants