process.chdir() is not supported in workers (--no-threads doesn't work)
See original GitHub issueDescribe the bug
When I try to call process.chdir
in a test, I get “TypeError: process.chdir() is not supported in workers”. From #566 I understand the solution is passing --no-threads
but it doesn’t seem to work.
Reproduction
https://stackblitz.com/edit/node-ve8ywd?file=package.json
System Info
System:
OS: Linux 5.4 Linux Mint 20.3 (Una)
CPU: (8) x64 Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
Memory: 3.70 GB / 15.52 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 18.2.0 - /usr/local/bin/node
Yarn: 1.22.11 - ~/.npm-global/bin/yarn
npm: 8.5.1 - ~/.npm-global/bin/npm
Browsers:
Chrome: 102.0.5005.61
Firefox: 101.0
npmPackages:
vitest: ^0.13.1 => 0.13.1
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:14 (9 by maintainers)
Top Results From Across the Web
process.chdir is not available in workers · Issue #566 - GitHub
TypeError : process.chdir() is not supported in workers. Is there a way to opt certain tests to not run in a worker?
Read more >Process.chdir() has no effect on require - Stack Overflow
I'd like to be able to trick require into thinking that the current working directory is the project root. The example above does...
Read more >Node.js process.chdir() Method - GeeksforGeeks
The process.chdir() method is an inbuilt application programming interface of the process module which is used to change the current working ...
Read more >z/OS UNIX reason codes - IBM
The rmdir service vnode operation is not supported. Action: Verify that the operation was performed on a physical file system that supports the...
Read more >uWSGI Options — uWSGI 2.0 documentation - Read the Docs
parser : uwsgi_opt_set_int. help : spawn the specified number of workers/processes ... help : do not enable harakiri during after-request-hook ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So what’s the path forward here? Simply not using
process.chdir
doesn’t seem like a reasonable forward path.The use case we currently support in many packages is creating a tmp dir or npm package using something like
fixturify-project
, and use that directory as a fixture for tests. At the end of the test, we dispose of the test directory, which requires us to switch directories before to support OS tests such aswindows-latest
, which will error if you try to rm a directory when it’s the current dir.This seems like a reasonably common usage, and we were previously using
--no-threads
withvitest
when we needed to support this scenario. Now that--no-threads
no longer works for this use case, there doesn’t seem to be a workaround.I understand that this is a larger issue with threads and changing directories, but it seems like we could collectively figure out a solution.
I already tried it, but communication was really slow: https://github.com/vitest-dev/vitest/pull/1790 You can tackle it, if you want.