yarnpkg / yarnpkg/berry

[Bug?]: yarn does not respect publishConfig when using portal protocol

Open
#5,641 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Self-service
  • I'd be willing to implement a fix
Describe the bug

I'm planning to use a local package for development.

It's package.json looks like this:

{
  "main": "src/index.ts",
  "type": "module",
  "scripts": {
    "build": "tsc",
  },
  "keywords": [],
  "exports": {
    "./src/*": "./src/*.ts",
    ".": "./src/index.ts",
  },
  "publishConfig": {
    "access": "public",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",
    "exports": {
      "./src/*": "./dist/*.js",
      ".": {
        "types": "./dist/index.d.ts",
        "module": "./dist/index.js",
        "import": "./dist/index.js"
      }
    }
  }
}

(This package is inside a workspace, so we need it's non-publish exports default to ts file)

When linking this package to a project by:

yarn link -p ../workspace/project-name

All the imports are resolved to ts file but not js file after build.

To reproduce
yarn link -p ../workspace/project-name
Environment
System:
    OS: Linux 6.4 Arch Linux
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  Binaries:
    Node: 18.16.1 - /tmp/xfs-d4b44f58/node
    Yarn: 3.6.0 - /tmp/xfs-d4b44f58/yarn
    npm: 9.5.1 - ~/.config/nvm/versions/node/v18.16.1/bin/npm
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with yarn link -p ../workspace/project-name using the package.json shown, then trace Yarn's portal linking and publishConfig handling. Done means linked imports use the publishConfig JavaScript and declaration paths after the package is built, while preserving the workspace's TypeScript development exports.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.