yarnpkg / berry

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

[Bug?]: Install with resolutions throws error: "Assertion failed: Expected the root to be registered" #3144

Open tim-stasse opened 3 years ago

tim-stasse commented 3 years ago

Self-service

Describe the bug

Adding resolutions for emotion packages breaks yarn install.

To reproduce

await packageJson({
    name: 'workspace-package',
    dependencies: {
        "@emotion/react": "^11.4.0",
        "@emotion/styled": "^11.3.0",
        "@storybook/react": "^6.3.4"
    },
}, { cwd: 'workspace-package/' })

const installPromise = packageJsonAndInstall({
    name: 'root',
    private: true,
    workspaces: [
        'workspace-package/',
    ],
    resolutions: {
        "@emotion/core@^10.1.1": "npm:@emotion/react@^11.1.5",
        "@emotion/styled@^10.0.27": "npm:@emotion/styled@^11.1.5",
        "emotion-theming@^10.0.27": "npm:@emotion/react@^11.1.5"
    }
})

await expect(installPromise).resolves.toBeTruthy()

Environment

System: OS: Linux 5.4 Ubuntu 18.04.5 LTS (Bionic Beaver) CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Binaries: Node: 14.17.1 - /tmp/xfs-6e044c2a/node Yarn: 3.0.0-rc.11.git.20210719.hash-e918c483 - /tmp/xfs-6e044c2a/yarn npm: 6.14.13 - ~/.nvm/versions/node/v14.17.1/bin/npm

Additional context

The install command only fails if a resolution is set for both @emotion/core and emotion-theming — note that the resolution for both @emotion/core and emotion-theming is the same (i.e. npm:@emotion/react@^11.1.5) — but if only one of those packages is given a resolution, then the install command succeeds.

e.g. Both of the following examples succeed

await packageJson({
    name: 'workspace-package',
    dependencies: {
        "@emotion/react": "^11.4.0",
        "@emotion/styled": "^11.3.0",
        "@storybook/react": "^6.3.4"
    },
}, { cwd: 'workspace-package/' })

const installPromise = packageJsonAndInstall({
    name: 'root',
    private: true,
    workspaces: [
        'workspace-package/',
    ],
    resolutions: {
        "@emotion/core@^10.1.1": "npm:@emotion/react@^11.1.5",
        "@emotion/styled@^10.0.27": "npm:@emotion/styled@^11.1.5"
    }
})

await expect(installPromise).resolves.toBeTruthy()
await packageJson({
    name: 'workspace-package',
    dependencies: {
        "@emotion/react": "^11.4.0",
        "@emotion/styled": "^11.3.0",
        "@storybook/react": "^6.3.4"
    },
}, { cwd: 'workspace-package/' })

const installPromise = packageJsonAndInstall({
    name: 'root',
    private: true,
    workspaces: [
        'workspace-package/',
    ],
    resolutions: {
        "@emotion/styled@^10.0.27": "npm:@emotion/styled@^11.1.5",
        "emotion-theming@^10.0.27": "npm:@emotion/react@^11.1.5"
    }
})

await expect(installPromise).resolves.toBeTruthy()
yarnbot commented 3 years ago

We couldn't reproduce your issue (all the assertions passed on master).

yarnbot commented 3 years ago

This issue reproduces on master:

Error: expect(received).resolves.toBeTruthy()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js install

➤ YN0000: ┌ Resolution step
::group::Resolution step
➤ YN0061: │ querystring@npm:0.2.1 is deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
➤ YN0061: │ urix@npm:0.1.0 is deprecated: Please see https://github.com/lydell/urix#deprecated
➤ YN0061: │ resolve-url@npm:0.2.1 is deprecated: https://github.com/lydell/resolve-url#deprecated
➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ fsevents@npm:2.3.2: Implicit dependencies on node-gyp are discouraged
➤ YN0061: │ uuid@npm:3.4.0 is deprecated: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
➤ YN0061: │ querystring@npm:0.2.0 is deprecated: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
➤ YN0061: │ chokidar@npm:2.1.8 is deprecated: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
➤ YN0061: │ fsevents@npm:1.2.13 is deprecated: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
➤ YN0032: │ evp_bytestokey@npm:1.0.3: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ nan@npm:2.14.2: Implicit dependencies on node-gyp are discouraged
➤ YN0001: │ Error: Assertion failed: Expected the root to be registered
    at applyVirtualResolutionMutations (/github/workspace/packages/yarnpkg-core/sources/Project.ts:2159:13)
    at Project.resolveEverything (/github/workspace/packages/yarnpkg-core/sources/Project.ts:810:5)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at /github/workspace/packages/yarnpkg-core/sources/Project.ts:1402:7
    at StreamReport.startTimerPromise (/github/workspace/packages/yarnpkg-core/sources/StreamReport.ts:309:14)
    at Project.install (/github/workspace/packages/yarnpkg-core/sources/Project.ts:1401:5)
    at /github/workspace/packages/plugin-essentials/sources/commands/install.ts:318:7
    at Function.start (/github/workspace/packages/yarnpkg-core/sources/StreamReport.ts:131:7)
    at YarnCommand.execute (/github/workspace/packages/plugin-essentials/sources/commands/install.ts:312:20)
::endgroup::
➤ YN0000: └ Completed in 7s 813ms
➤ YN0000: Failed with errors in 7s 816ms
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-0c0da74930.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:24:7)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.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-91cf93ba72.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-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
tim-stasse commented 3 years ago

FYI it looks like Sherlock was picking up the extra success examples I added (I'd originally used the ```js repro tag — instead of just the \'\'\'js tag) while ignoring the [first] failing repro, and then reported the issue as unreproducible despite having a failure.