Skip to content

[npm] Dependencies of optionalDependencies are not installed #437

Description

@t2ym

[npm] Dependencies of optionalDependencies are not installed

Root Cause

  • Npm says dependencies of file:folder references are not installed but just symlinks to the file:folder packages are created AS DESIGNED
  • This behavior is different in NPM 6

Workarounds

  • OPTION # 1: Use npm version 6 and perform npm i twice
  • OPTION # 2: Use a tgz package file instead of thin-hook package on the repo as follows:
    • Note: This behavior may change in the future npm
cd $PROJECTDIRECTORY
rm -v thin-hook-*.tgz # clean up archives
npm pack thin-hook # create the latest archive such as thin-hook-0.4.0-alpha.57.tgz
npm i thin-hook-*.tgz # install from the tgz archive
npm i # install optionalDependencies and dependencies of the optionalDependencies
rm -v thin-hook-*.tgz # clean up archives
  • OPTION # 3: Install as a tgz package via package.json scripts
    • Notes
      • --save-optional avoids errors at the first installation
      • In postinstall script, npm i is called recursively once
{
  "scripts": {
    "preinstall": "if [ ! -f thin-hook-0.4.0-alpha.57.tgz ]; then npm pack thin-hook@0.4.0-alpha.57; fi",
    "postinstall": "if [ ! -f node_modules/thin-hook/package.json ]; then npm i --save-optional thin-hook-0.4.0-alpha.57.tgz; npm i; else if [ ! -f node_modules/reportage/package.json ]; then npm i; fi; fi",
  },
}
  • OPTION # 4: Copy nested plugin dependencies explicitly after npm i thin-hook@^0.4.0-alpha.57 --install-links=true
    • Notes:
      • npm i again since package-lock.json is (strangely) inconsistent after the npm i thin-hook@^0.4.0-alpha.57 --install-links=true installation
      • Verified with npm@9.8.1
      • If npm i --install-links=true is executed without the explicit thin-hook package name, the plugins are unexpectedly installed at node_modules/thin-hook/node_modules/@thin-hook/* instead of the expected node_modules/@thin-hook/*, which is the reason why the explicit package name is required
      • There is, of course, another option that the nested dependencies are copied from node_modules/thin-hook/node_modules/@thin-hook/*/node_modules instead of node_modules/@thin-hook/*/node_modules.
      • As of 0.4.0-alpha.57, the plugin with any nested dependencies that have to be explicitly copied is only @thin-hook/injector-helpers
{
  "scripts": {
    "preinstall": "if [ ! -f node_modules/reportage/package.json ]; then npm i thin-hook@0.4.0-alpha.57 --install-links=true; fi",
    "install": "cd node_modules/@thin-hook/; for i in *; do { if [ -d $i/node_modules ] && [ ! -d ../thin-hook/plugins/$i/node_modules ]; then cp -rv $i/node_modules ../thin-hook/plugins/$i/; fi; } done;",
    "postinstall": "grep '\"resolved\": \"file:node_modules/thin-hook/plugins/about-blank-redirector\"' package-lock.json; if [ \"$?\" = \"0\" ]; then npm i; fi",
  },
  "dependencies": {
    "thin-hook": "0.4.0-alpha.57"
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions