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

pnpm install recursive fails with bin in sub package that must be compiled first #1801

Closed
hgossler opened this issue Apr 30, 2019 · 20 comments · Fixed by #6728
Closed

pnpm install recursive fails with bin in sub package that must be compiled first #1801

hgossler opened this issue Apr 30, 2019 · 20 comments · Fixed by #6728
Assignees
Labels
area: lifecycle-scripts area: monorepo Everything related to the pnpm workspace feature size: M-L type: bug
Projects

Comments

@hgossler
Copy link

pnpm version:

v3.2.0

Code to reproduce the issue:

See https://github.com/hgossler/pnpm-issue-1801 and follow the steps in the readme. This fails because pnpm attempts to chmod the bin in sub-package1 before the prepare script is run.

Expected behavior:

pnpm i -r should work.

Actual behavior:

 ERROR  ENOENT: no such file or directory, chmod '... /pnpm-issue-2/packages/sub-package2/node_modules/sub-package1/dist/script.js'

It works if you run

cd packages/sub-package1
pnpm i

first.

Additional information:

  • node -v prints: v11.10.1
  • Windows, OS X, or Linux?: macOS
@LukasHechenberger
Copy link

Any progress on this one? Or is there a workaround?

@zkochan
Copy link
Member

zkochan commented Feb 13, 2020

No, this is not an easy to fix issue.

A workaround would be to create a bin file that just requires the compiled bin file. That's how it is done in pnpm repo as well: https://github.com/pnpm/pnpm/blob/main/packages/pnpm/bin/pnpm.cjs

@LukasHechenberger
Copy link

Okay, that’s not possible in my case. I did work around it by touching the bin file in a preinstall script. Works fine as far as I can tell by now... Thanks for the incredibly fast support!

@develar
Copy link

develar commented Mar 13, 2021

So, any project that uses Typescript and monorepo is not able to use PNPM without some kind of workaround. Hmm....

 ERROR  ENOENT: no such file or directory, chmod '/home/circleci/project/test/node_modules/electron-builder/out/cli/cli.js'

@develar
Copy link

develar commented Mar 13, 2021

And no way to ask to not create bin links... #459

@zkochan
Copy link
Member

zkochan commented Mar 13, 2021

So, any project that uses Typescript and monorepo is not able to use PNPM without some kind of workaround.

not any project. This is not such a frequent scenario. It only fails if a workspace project with a compiled bin file is used in a postinstall script of another workspace project.

@develar
Copy link

develar commented Mar 13, 2021

not any project. This is not such a frequent scenario. It only fails if a workspace project with a compiled bin file is used in a postinstall script of another workspace project.

No, in my case no postinstall. Just regular bin file that not referenced in postinstall script. You can find example in electron-userland/electron-builder#5710 (branch tsc-pnpm).

"electron-builder": "./out/cli/cli.js",
 "install-app-deps": "./out/cli/install-app-deps.js"

As workaround, I added plain JS files.

@zkochan
Copy link
Member

zkochan commented Mar 13, 2021

oh, right. You are correct. If it is not used in a postinstall, there is a workaround to put regular js file wrappers. We do that in the pnpm monorepo as well: https://github.com/pnpm/pnpm/tree/main/packages/pnpm/bin

Maybe as a fast workaround, we could make pnpm create the command shims even if the target does not exist yet.

@develar
Copy link

develar commented Mar 13, 2021

Correction — looks like indeed "not any project." In my project there is a dependency on electron-builder. test depends on electron-builder and looks like that PNPM tries to create bin links because of that. But were no issues in case of Yarn 2.

@kashpatel
Copy link

kashpatel commented Nov 17, 2021

This was a problem in our project monorepo. As a workaround, I started committing built js file bin command point to.

@estrattonbailey
Copy link
Sponsor

In case it's helpful, I did similar in my Github workflows.

      - name: pnpm - output bin stubs
        run: echo "#! /usr/bin/env node" > ./packages/presta/cli.js
      - name: pnpm - install
        run: pnpm install

@Akryum
Copy link

Akryum commented Dec 6, 2021

Still having this issue if a workspace in my monorepo has a bin file that doesn't exist yet (and I don't have any postinstall scripts):
https://github.com/Akryum/peeky/runs/4429592483?check_suite_focus=true
https://github.com/Akryum/peeky/blob/fec6b43830ba3d7821c0de7b6327fbc755b7aa37/packages/peeky-cli/package.json#L20

Using PNPM 6.23.1


Also reproduced when cloning the repo and executing pnpm i, which is rather annoying 😅

@Akryum
Copy link

Akryum commented Dec 6, 2021

Ugly workaround in the meantime:

akryum@Square:~/Projects/peeky$ npm run fix-pnpm-bin

> peeky-mono-repo@0.5.2 fix-pnpm-bin
> mkdir ./packages/peeky-cli/dist && touch ./packages/peeky-cli/dist/bin.js

akryum@Square:~/Projects/peeky$ pnpm i
Scope: all 10 workspace projects
Lockfile is up-to-date, resolution step is skipped
Packages: +957
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 957, reused 957, downloaded 0, added 0, done
node_modules/.pnpm/core-js-pure@3.19.3/node_modules/core-js-pure: Running postinstall script, done in 41ms
node_modules/.pnpm/@apollo+protobufjs@1.2.2/node_modules/@apollo/protobufjs: Running postinstall script, done in 38ms
node_modules/.pnpm/vue-demi@0.12.1_vue@3.2.24/node_modules/vue-demi: Running postinstall script, done in 68ms
node_modules/.pnpm/nodemon@2.0.15/node_modules/nodemon: Running postinstall script, done in 49ms
node_modules/.pnpm/esbuild@0.13.15/node_modules/esbuild: Running postinstall script, done in 46ms
akryum@Square:~/Projects/peeky$

@zkochan zkochan added this to Priority in Status Dec 6, 2021
@yankeeinlondon
Copy link

also still present in 6.24.3

@zkochan
Copy link
Member

zkochan commented Feb 10, 2022

Installation doesn't fail since v6.24.4, if the target bin doesn't exist. Just a warning is printed. This was change in this PR: #4172

@AlexAegis
Copy link

AlexAegis commented Nov 8, 2022

Could the "bin linking" step be re-tried for the failed links after the last install hook finished? (If a postinstall script happened to build it, it would be there)

Or to expose it as cli, so we could plug it in ourselves as a postbuild step too.

@trappar
Copy link

trappar commented Feb 25, 2023

I just ran into this issue and submitted a PR for the underlying library (see above) which would fix it 🤞🏻

@kenbankspeng
Copy link

Having this issue on pnpm 8.6.2 and it prevents me from using pnpm on any NextJS 13 project.

@eckdanny
Copy link

Me:

  1. workspace root depends on a workspace pkg that has a compile step to produce a bin
  2. Uh Oh! I have a chicken-and-egg problem that is confounding CI
  3. found this thread, looked at diff in fix: link local bins created by postinstall scripts #6728 (specifically here)
  4. use a prepare lifecycle script in the bin-producing pkg
  5. ✅ all good

FWIW: My bin-producing pkg is written in typescript and my workaround before adding a prepare, was to point the <pkgJson>#bin: at index.ts, and add ts-node as devDependency to workspace root. This was useful for developing the pkg, but prepare is more idiomatic solution for satisfying the chicken-and-egg linking problem.

Pkmmte added a commit to Wave-Play/robo.js that referenced this issue Sep 5, 2023
@webpro
Copy link

webpro commented Sep 14, 2023

I jotted down a scrap about this: https://www.webpro.nl/scraps/compiled-bin-in-typescript-monorepo. Maybe it's helpful, please let me know it contains errors (it worked for me).

dalechyn added a commit to AbstractSDK/abstract.js that referenced this issue Dec 28, 2023
dalechyn added a commit to AbstractSDK/abstract.js that referenced this issue Dec 29, 2023
TV-T added a commit to TV-T/postgres-migrations that referenced this issue Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: lifecycle-scripts area: monorepo Everything related to the pnpm workspace feature size: M-L type: bug
Projects
Archived in project
Status
Priority
Development

Successfully merging a pull request may close this issue.