Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[npm] Dependencies of optionalDependencies are not installed #437

Open
t2ym opened this issue Jul 26, 2023 · 0 comments
Open

[npm] Dependencies of optionalDependencies are not installed #437

t2ym opened this issue Jul 26, 2023 · 0 comments

Comments

@t2ym
Copy link
Owner

t2ym commented Jul 26, 2023

[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 [email protected]; 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 [email protected]
      • 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 [email protected] --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"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant