Is it possible to use Cygwin on Windows to develop Node.js apps with Yarn?

Viewed 889

I would like to get started with, and use yarn.

I am using cygwin on windows, I launch and type:

$yarn init

and I get:

$ yarn init
yarn init v1.12.3
error An unexpected error occurred: "Can't answer a question unless a user TTY".
info If you think this is a bug, please open a bug report with the information provided in "C:\\home\\code\\repos\\pwa\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/init for documentation about this command.

What does means: "Can't answer a question unless a user TTY"?

Am I prevented from using a bash shell provided by cygwin with yarn? I could not find any document telling me what terminal/shell I should download and use.

I need to be productive using my bash shell with scripts, aliases, command line completion, and have access to a full range of gnu commands for scripting and so therefore a DOS command prompt or powershell is not an option.

1 Answers

Yes!

TL;DR: Update to the latest yarn version. Skip to the end to see how to get the latest version. It is NOT as simple as it sounds.

I believe it could be done in yarn 1.x if you modify the /c/Program Files/nodejs/yarn file to work correctly with cygwin. I don't get why that script was written the way it was, but I can see why it wouldn't work on the cygwin terminal: for some paths, it converts them to windows paths, then appends linux paths to the end of it. I bet if you modify that to use linux (i.e., cygwin) paths, yarn 1.x will run correctly.

But, this is not a great answer because it's all hypothetical. Luckily, there's an even simpler solution that isn't hypothetical: upgrade to the latest yarn. Once I did this, cygwin worked correctly. They probably fixed a bug in the older versions.

You may be saying to yourself, "I just ran npm install yarn so I already have the latest version." That doesn't mean you have the latest yarn. For some reason, that installs the latest version of 1.x. The latest version of yarn is 3.x.

Also, to go from 1.x to latest, you need to run some ad-hoc commands -- as opposed to npm installing something else.

Here is the guide to go from yarn 1.x to latest:

  1. Run npm install -g yarn to update the global yarn version to latest v1

  2. Go into your project directory

  3. Run yarn set version berry to enable v2

  4. If you used .npmrc or .yarnrc, you'll need to turn them into the new format

  5. Add nodeLinker: node-modules in your .yarnrc.yml file

    I don't know what step 4 means. But my current .yarnrc looks like this:

    yarnPath: ".yarn/releases/yarn-berry.cjs"
    nodeLinker: node-modules
    
  6. Commit the changes so far (yarn-X.Y.Z.js, .yarnrc.yml, ...)

  7. Run yarn install to migrate the lockfile

  8. Use yarn the way you normally would.

Related