-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Postinstall script is not being executed #5476
Comments
From a quick test on OSX, Node 8.10, yarn 1.5.1 it seemed to work OK:
(adding pkgA to pkgB runs pkgA's postinstall script, creating post.txt) Could you provide a full example? |
@rally25rs, your test seems to work fine. But I can confirm that this is an issue with my package: Yarn: $ yarn --version
1.5.1
$ yarn add -D clean-slate-lint
yarn add v1.5.1
warning package.json: No license field
warning [email protected]: No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
warning [email protected]: No license field
✨ Done in 2.43s. No message and nothing was added to the package.json as expected with this package. Npm: $ npm i --save-dev clean-slate-lint
> [email protected] install /Users/tombonnike/Desktop/test/node_modules/husky
> node lib/installer/bin install
husky > setting up git hooks
husky > done
> [email protected] postinstall /Users/tombonnike/Desktop/test/node_modules/clean-slate-lint
> ./bin/post-install.js
✅ clean-slate post-commit hooks setup succeeded.
+ [email protected]
added 121 packages from 66 contributors, removed 62 packages and updated 500 packages in 43.483s |
As a smaller reproduction case: $ cat ./pkgA/package.json
{
"name": "pkgA",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"postinstall": "node test.js"
}
}
$ cat ./pkgA/test.js
#!/usr/bin/env node
console.log('FOO BAR')
$ yarn add -D file:./pkgA
yarn add v1.5.1
warning package.json: No license field
warning [email protected]: No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
warning [email protected]: No license field
✨ Done in 0.24s.
|
Yeah, happens for the latest
while with Could be that the |
As an update, the script is being executed for me with Yarn v. 1.6. However, the output from the script is not being populated within cli. |
Same thing on 1.7. The script is being run, but no stdout/stderr is visible (unless the script fails). Is there a way for a postinstall script to flag that it wants some output printed as part of the regular install flow (e.g. advisory messages)? |
Using 1.12.3 but still no output from an install script is displayed. Any chance of this being changed? |
Please... |
There is a known issue where if a script's output doesn't contains an ending newline, then it's output gets overwritten by yarn's own output. It is possible your script is being run, just the output is not being displayed? |
I tried adding an ending newline, but still no luck. My code: https://github.com/nebrelbug/squirrelly/blob/master/postinstall.js |
@rally25rs so I don't believe that's the issue... On a side note, is there a way to test postinstall scripts without publishing a new version every time? |
FYI the postinstall script of full-icu is also not executed here. I'm on a Mac with:
The way the postinstall script is specified looks totally valid: https://github.com/unicode-org/full-icu-npm/blob/756b48ba6ece2b14051bd9107501f90fd98811ba/package.json#L5-L7 |
I'm at version Anyone know if there is a solution in sight? |
@rainboxx I'm at version |
@rally25rs Here is a repo to reproduce - https://github.com/aamorozov/nightwatch-typescript/ Yarn version - 1.15.2 |
Using yarn 1.16.0 and my |
I'm using yarn 1.19.1 with node v12.11.1 and I'm still having this issue. |
Can confirm that's the reason for me; I can get the |
Doesn't seem to be working with yarn v3.0.2 as well |
same as yarn v3.1.0. postinstall not excuted when excute yarn root package.json
package a package.json
|
Thx @jy617lee work for me with yarn 3 and workspace 👍🏻 |
Also chiming in: this is a potential problem for migrating a project that still has a Bower dependency. The issue is that yarn only re-runs postinstall when the package graph changes, but There are some Berry plugins that implement always-ran postinstall scripts but they don't have a lot of development effort behind them - I would like to be able to rely on something in the core tool. EDIT: My workaround was to write a small custom plugin that installed Bower as part of the |
I use node |
Yarn Version 1.22.19, It is working, My mistake was instead of putting the postinstall inside the script section, I put it outside. "scripts": {
"postinstall": "npx patch-package"
} |
Using yarn
|
I'm using Yarn
Thanks! |
Using yarn 3.6.1. "scripts": {
"postinstall": "node ./bin/postInstall",
} postinstall.js: #!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const childProcess = require('child_process');
const os = require('os');
/**
* Do all things that need to be done after installing packages
*/
const iosCommands = [
// on MacOS, fix images and install pods
{ command: 'npx react-native-fix-image' },
{ command: 'npx react-native setup-ios-permissions' },
{ command: 'npx pod-install' },
];
const commands = [
// Patch libraries for typescript errors.
{ command: 'npx patch-package' },
{ command: 'npx jetify' },
...(os.platform() === 'darwin' ? iosCommands : []),
// Make sure we're set up correctly
{ command: 'npx solidarity' },
];
commands.forEach(commandAndOptions => {
const { command, ...options } = commandAndOptions;
try {
childProcess.execSync(command, {
stdio: 'inherit',
...options,
});
} catch (error) {
process.exit(error.status);
}
}); Even if I deleted |
I had to resort to using Yarn Plugin After Install to have something fire after every This issue has been open for over 5 years... so is the idea of "post install" meant to: a) not work in Yarn (Classic) Could one of the Yarn project leads confirm if there is a real bug here (so we can work on getting some kind of fix) or if the intention is to replace this workflow with something different in newer versions of Yarn? |
I found that If I'am using node16 ,the postinstall script won't work. But work on node18. |
I have found this problem, So using PandaCss a prepare script is needed, i have tried using both prepare and postinstall, neither work if there is already a yarn.lock & yarn/cache. meaning that if there was ever an update to the outputted files by PandaCss i wouldn't get those changes. this is a problem and really needs looking into. or at least a solution suggested by the @yarnpkg team. |
Ouch, it looks like an option like npm's |
Facing the same thing. Any workaround possible so far? |
My general workaround suggestion is that you create an If you are too comfortable (like me) and don't want to type
It checks if you have a script named "install" in your package.json file, and if you defined it, then it will execute that. If it doesn't find an "install" script, then it will execute the simple So, if you really need a workaround:
The second part of my suggestion worked for me and I'm happy with it, but it's so hacky that I'm really not sure if I should post this to the public. 😅 People will talk.. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Postinstall script specified in the
package.json
is not being executed afteryarn add PACKAGE_NAME
If the current behavior is a bug, please provide the steps to reproduce.
If it can depend on the specifics of the script I can put together a repo to reproduce.
What is the expected behavior?
Postinstall script should be executed after
yarn add
installs the package. The script is being installed without any issues withinnpm install
.Please mention your node.js, yarn and operating system version.
node - 9.7.1
yarn - 1.5.1
MacOS Sierra
The text was updated successfully, but these errors were encountered: