question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] `--cwd` gets ignored when specified inside package.json script

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

{
  "scripts": {
    "foo": "yarn --cwd .yarn exec cd"
  }
}

Running yarn foo prints out the current path, not .yarn as specified in --cwd.

Running yarn --cwd .yarn exec cd directly in the shell produces the correct output.

To Reproduce

Use the following package.json

{
  "name": "foo",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "foo": "yarn --cwd .yarn exec cd"
  }
}

Run yarn foo from the package directorty.

Environment if relevant

  • OS: Windows 10 v2004
  • Node version: 12.13.1
  • Yarn version: 2.4.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
merceyzcommented, Jan 7, 2021

This is a valid issue, you’re running into https://github.com/yarnpkg/berry/pull/1812#discussion_r485873759, as a workaround you can specify the path as the first argument

yarn ../another/package exec pwd
5reactions
Mithrascommented, Mar 16, 2022

I don’t think --cwd is doing anything at all (inside or outside of package.json). It can be confirmed with a simple yarn --cwd /expected exec pwd. Output would be anything but /expected. What exactly --cwd is supposed to be doing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm - run scripts in directory other than cwd - Stack Overflow
However it seems the first cd command is being ignored; the subsequent commands are being executed in the parent, not child, directory. I've ......
Read more >
Configuration options | Yarn - Package Manager
Files matching the following patterns (in terms of relative paths compared to the root of the project) will be ignored by the yarn...
Read more >
Configuration Files - ESLint - Pluggable JavaScript Linter
JavaScript (ESM) - use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json . Note that ESLint does ...
Read more >
Configure Babel
babelrc documentation to see more configuration options. package.json. Alternatively, you can choose to specify your .babelrc.json config from within ...
Read more >
npm-check-updates
npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found