fab-spec / fab

💎 FAB project specification & monorepo
https://fab.dev
MIT License
579 stars 37 forks source link

Yarn Berry - missing transitive deps on init #352

Open osdiab opened 3 years ago

osdiab commented 3 years ago

Issue

  1. Install fab cli in a yarn berry project by running yarn add -D @fab/cli (I did this since npx fab init fails as well if I just run it like that)
  2. Run yarn fab init to init the project
  3. Get this failure due to a missing dep in @fab/core:
(node:42371) Error Plugin: @fab/cli: could not find package.json with {
  type: 'core',
  root: '/Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_modules/@fab/cli',
  name: '@oclif/plugin-help'
}
module: @oclif/config@1.17.0
task: loadPlugins
plugin: @fab/cli
root: /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_modules/@fab/cli
See more details with DEBUG=*
(Use `node --trace-warnings ...` to show where the warning was created)
    Error: @fab/core tried to access json-keys-sort, but it isn't declared in its dependencies; this makes the require 
    call ambiguous and unsound.

    Required package: json-keys-sort (via "json-keys-sort")
    Required by: @fab/core@npm:1.0.0-rc.3-beta.1 (via /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-core-npm-1.
    0.0-rc.3-beta.1-21bf8f1a52-e90d9306d2.zip/node_modules/@fab/core/lib/models/)

    Require stack:
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-core-npm-1.0.0-rc.3-beta.1-21bf8f1a52-e90d9306d2.zip/node_m
    odules/@fab/core/lib/models/ProtoFab.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-core-npm-1.0.0-rc.3-beta.1-21bf8f1a52-e90d9306d2.zip/node_m
    odules/@fab/core/lib/index.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_mo
    dules/@fab/cli/lib/commands/init.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@oclif-config-npm-1.17.0-acbde241aa-52b5803062.zip/node_modules/
    @oclif/config/lib/plugin.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@oclif-config-npm-1.17.0-acbde241aa-52b5803062.zip/node_modules/
    @oclif/config/lib/config.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@oclif-config-npm-1.17.0-acbde241aa-52b5803062.zip/node_modules/
    @oclif/config/lib/index.js
    - /Users/omar/code/personal/omardiab.com/.yarn/$$virtual/@oclif-command-virtual-04fd8fde04/0/cache/@oclif-command-npm
    -1.8.0-8a2dc2935e-d0591e56ce.zip/node_modules/@oclif/command/lib/command.js
    - /Users/omar/code/personal/omardiab.com/.yarn/$$virtual/@oclif-command-virtual-04fd8fde04/0/cache/@oclif-command-npm
    -1.8.0-8a2dc2935e-d0591e56ce.zip/node_modules/@oclif/command/lib/index.js
    - /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_mo
    dules/@fab/cli/bin/run
    Code: MODULE_NOT_FOUND

Solution

Add the dep explicitly to @fab/core

Workaround

Add this to yarnrc.yml:

packageExtensions:
  "@fab/core@*":
    dependencies:
      "json-keys-sort": "*"
osdiab commented 3 years ago

For my nextJS project I also had a few more missing declarations

  "@fab/core@*":
    dependencies:
      json-keys-sort: "*"
  "@fab/cli@*":
    dependencies:
      "@fab/actions": "*"
  "@fab/actions@*":
    dependencies:
      pretty-bytes: "*"

and ultimately PNP seems to be breaking fab when running fab build:

Error Plugin: @fab/cli: could not find package.json with {
  type: 'core',
  root: '/Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_modules/@fab/cli',
  name: '@oclif/plugin-help'
}
module: @oclif/config@1.17.0
task: loadPlugins
plugin: @fab/cli
root: /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-cli-npm-1.0.0-rc.3-beta.1-058dd416eb-a0bb7e6833.zip/node_modules/@fab/cli
See more details with DEBUG=*
(Use `node --trace-warnings ...` to show where the warning was created)
       [Builder] 💎 fab build 💎
       [Builder] Reading plugins from config.
Build failed!

Error occurred requiring /Users/omar/code/personal/omardiab.com/.yarn/cache/@fab-input-nextjs-npm-1.0.0-rc.3-beta.1-c0001e227b-c309455394.zip/node_modules/@fab/input-nextjs/build.js.
Maybe it's using syntax that NodeJS can't interpret?
See https://fab.dev/kb/plugins#restrictions for more info.
    Error: Build failed!

Looks like yarn berry support isn't quite there yet lol