-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Bug] Some bin scripts not working in CI environment with nodeLinker: node-modules
#2416
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
Comments
In your repro, your Is there any reason why you don't add a dependency to |
I avoided it because eslint is bundled within react-scripts (CRA/create react app) and CRA is opinionated about this and some other libraries - expecting developers to rely on their bundled version of eslint rather than adding the dependency itself. I thought yarn2 was only more strict when it comes to using PnP? The migration guide only suggests using @yarnpkg/doctor once switching over to PnP. ESLint specifically is discussed in this issue: #8 and has a specific mention for CRA:
But, again, my understanding was that this is only relevant for PnP? Additionally, the build shows that ts-node and prettier are both failing, even though they are explicitly listed as dependencies. |
They're listed as dependencies in your root, but they should be dependencies in each workspace as well. Alternatively you can define the script in the root |
Yes, with one caveat: the environment created by The With that being said, if you list prettier as a dependency and it's not available, then something is wrong. I'm not aware of any problem in this part of the code though, so I'd tend to think perhaps the cwd is incorrect when executing the command (you need to be in the workspace that defines prettier as dependency). |
Thank you both. TLDR Resolution for reference. In a workspaced environment - even if using Rest.. @andreialecu adding the dependency to the specific workspace fixed the issue, as did using a shared script - an example of shared script included below for reference: In root package.json "scripts": {
"g:lint": "cd $INIT_CWD && eslint --ext js,ts,tsx src",
"g:pretty-check": "cd $INIT_CWD && prettier --list-different './**/*.{js,json,ts,tsx,md,yml}'"
},
"devDependencies": {
"eslint": "^7.18.0",
"prettier": "^2.2.1",
"ts-node": "^9.1.1"
} In pkg1 package.json "scripts": {
"lint": "yarn g:lint",
"pretty-check": "yarn g:pretty-check"
}, (green build: https://github.com/bhishp/yarn-2-workflow-bin-repro/runs/1777056188) @arcanis thank you for the explanation, is it worth adding something to the migration guide for this? Anything I can help with? Closing this issue, thanks for your help |
With regards to this, I am only seeing the behaviour in a CI environment, is there any obvious reason why these commands work locally but not in CI? Especially given that the yarn-berry runner is checked-in to the repo |
Do you have |
@bhishp Perhaps you have some version |
We also have this issue and not sure what the fix should be. root scripts look like this...
SST uses AWS CDK to run the UPDATE --- Something that worksI tested with my own simple script ...
and adding to package.json scripts
then running Work aroundFound out by also adding the |
I meet this problem too. |
Uh oh!
There was an error while loading. Please reload this page.
Thank you for your work on yarn and on-going improvements. Caveat, I am just upgrading to yarn 2 so this may be down to some naïvety on my part. Thank you in advance for your help.
Describe the bug
I am doing a migration from yarn1 to yarn2 for my workspaced monorepo. I have upgraded the version to
yarn-berry
and still only usingnodeLinked: node-modules
. The problem I'm having is that some of my existing scripts that execute packages from the bin directory do not work when they are in a CI environment, however they do work locally.Example script
"lint": "eslint --ext js,ts,tsx src --max-warnings=0"
Locally this executes as expected, on CI the output is:
command not found: eslint
. Note, this has also happened with a script that usests-node
, so is not exclusive to eslint.Workaround
I have verified that the eslint package is actually being installed on the CI environment and it seems I can get around this by invoking the bin directly, as such:
"lint": "../../../node_modules/.bin/eslint --ext js,ts,tsx src"
This is a sub-optimal solution for a few reasons but proves the lint package is there in bin and able to be executed. It feels like yarn is unable to resolve to the bin directory for some reason, maybe because of workspaces?
Only some packages
As I mentioned, this doesn't seem to happen for everything, we also have a prettier script that runs which is working fine:
"pretty-check": "prettier --config ./.prettierrc --list-different './**/*.{js,json,ts,tsx,md,yml}'"
My understanding is that bin scripts like this need to be treated differently PnP linker is being used, but I would think there is no impact if still using node-modules?
To Reproduce
Minimum reproduction repo available here: https://github.com/bhishp/yarn-2-workflow-bin-repro
I fresh-installed yarn 2 with a workspace config and two create-react-app packages and implemented some of the scripts mentioned above. Locally all the scripts work but once in CI environment the problems occur.
Failing build with lint scripts: https://github.com/bhishp/yarn-2-workflow-bin-repro/runs/1776495972?check_suite_focus=true
Failing build with ts-node script (though explicitly added as a dependency): https://github.com/bhishp/yarn-2-workflow-bin-repro/runs/1776516171?check_suite_focus=true
Failing build with prettier script (though explicitly added as a dependency): https://github.com/bhishp/yarn-2-workflow-bin-repro/runs/1776471730
☝🏽 This prettier script is working in my actual project but failing in this reproduction
Screenshots
Workflow output of failed script,
command not found: eslint
:Environment if relevant (please complete the following information):
runs-on: ubuntu-latest
Additional context
This monorepo consists of 4 packages, 3 of which are CreateReactApp projects, mentioned because CRA bundles eslint (though this issue happens with other bins too).
yarnrc.yml for reference:
root-level package.json:
The text was updated successfully, but these errors were encountered: