yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: Self Reference Symlinks Are not Created #5466

Open nezartarbin opened 1 year ago

nezartarbin commented 1 year ago

Self-service

Describe the bug

The yarnpkg.org protocols page talks about self reference support. "Tip: Yarn 2 implements support for self-references ...". I tried it on a simple project (no babel, typescript, etc) and it unfortunately does not work.

This feature seems scarcely documented. My suspicion is that this feature only works with workspaces or with yarn PnP, but this requirement is not mentioned anywhere, so I presumed this behavior is unintended

Error message:

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'somename' imported from /code/somedir/second.js
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:783:9)
    at moduleResolve (node:internal/modules/esm/resolve:832:20)
    at defaultResolve (node:internal/modules/esm/resolve:1069:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:305:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:156:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:33)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.2.0

To reproduce

const fs = require('fs')

fs.writeFileSync('.yarnrc.yml', 'nodeLinker: node-modules \r\n')

await packageJson({ name: 'somename', "type": "module",
    dependencies: {
        "fastify": "^4.17.0",
    },
})
await yarn('install')
expect(fs.existsSync('node_modules/somename')).toBe(true)

non-sherlock steps to reproduce:

export default someFunc;

- create file second.js. import first.js as ES Module and invoke the function:

import someFunc from 'somename/first.js';

someFunc();


run second.js: `node somedir/second.js`

you will get the error above.

using --preseve-symlinks does not work either.

### Environment

```shell
System:
    OS: Linux 6.3 Gentoo Linux
    CPU: (8) x64 AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
  Binaries:
    Node: 20.2.0 - /tmp/xfs-77868d5e/node
    Yarn: 3.5.1 - /tmp/xfs-77868d5e/yarn
    npm: 9.6.6 - /usr/bin/npm

Additional context

No response

yarnbot commented 1 year ago

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

Expected: true
Received: false
    at module.exports (evalmachine.<anonymous>:12:48)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
yarnbot commented 1 year ago

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

Expected: true
Received: false
    at module.exports (evalmachine.<anonymous>:12:48)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)