`yarn bundle` throwing error `ENOENT: no such file or directory`
See original GitHub issueDescribe the bug I have a yarn workspace, I am trying to use this plugin to bundle and create docker images. When I try to bundle a package to be dockerized, I get an error:
Internal Error: ENOENT: no such file or directory, stat '/private/var/folders/0x/cml8jk85195dd8p2f1swfrb00000gn/T/xfs-764eefc3/node_modules/@connext/nxtp-router'
at Object.statSync (node:fs:1536:3)
at ar.statSync (/Users/rahul/.node/corepack/yarn/3.2.0/yarn.js:319:2861)
at Ht.removeEmptyDirectories (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:44:4895)
at Ht.removeEmptyDirectories (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:44:4992)
at async Ht.removeEmptyDirectories (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:44:4981)
at async Ht.removeEmptyDirectories (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:44:4981)
at async Ht.removeExcluded (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:44:5630)
at async t (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:45:1313)
at async ar.mktempPromise (/Users/rahul/.node/corepack/yarn/3.2.0/yarn.js:319:63472)
at async Ht.execute (/Users/rahul/connext/repos/nxtp/.yarn/plugins/@ojkelly/plugin-all.cjs:45:2653)
To Reproduce Steps to reproduce the behavior:
- Checkout this repo on branch
amarok: https://github.com/connext/nxtp/tree/amarok - Run
yarn bundleinpackages/agents/sequencer - See error
Expected behavior Bundle happens.
Screenshots

Desktop (please complete the following information):
- OS: macOS
Additional context
Yarn version: 3.2.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top Results From Across the Web
yarn install fails with `ENOENT: no such file or directory ...
Running yarn install as part of a build step for a Docker image based on node:7 fails on Travis CI with ENOTEMPTY, EEXISTS...
Read more >npm - Why does "yarn install" raise an ENOENT error when ...
I'm trying to migrate to Yarn. When I run yarn install in the console, it gives me an error: An unexpected error occurred:...
Read more >How to fix: npm ERR! enoent ENOENT: no such file or ...
I recently struggled for a while with an npm error thrown when executing npm install of some package. The error message was npm...
Read more >express error: enoent: no such file or directory, stat - You.com
Solution 1. First, don't use PWD. Just use __dirname. It works on Heroku exactly as it works anywhere else. Using PWD makes your...
Read more >Resolve npm WARN saveError ENOENT no such file or ...
To resolve the ENOENT warning message, you need to add a package.json file in the directory where you run the npm install command....
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

Nothing prevents copying all the files at the moment, as we’re using an os file copy to setup the tmp dir.
.bundleignoreprevents those files from hanging around in the final zip or in the tmp folder (usually done for docker).It sounds like you might be onto the right solution. If you’re interested in making a PR the relevant area is here https://github.com/ojkelly/yarn.build/blob/main/packages/plugins/plugin-bundle/src/commands/bundle/index.ts#L355
Otherwise I think I can get to solving this in the next few weeks.
I think an ideal approach is to take the
--excludefolders, and subtract them from a list of files to copy instead of taking a full copy of the whole repo.Yep fair. In this case the only point of that function
removeEmptyDirectoriesis to help the[removeExcluded](https://github.com/ojkelly/yarn.build/blob/f0bace2ef13d0e36cf54a739c43db3b76cd4fcf8/packages/plugins/plugin-bundle/src/commands/bundle/index.ts#L257)in reducing the size of the bundle.This error appeared around this code in the past https://github.com/ojkelly/yarn.build/pull/120 which fixed #119.
It’s preferable for the bundle to be marginally bigger, than break in some circumstances.
I think #142 is likely related to this, because it appears we’ve followed a path, and tried to delete something that does not exist.
If you’re able to provide a link to a repro I think I know where we need to look now. Otherwise, if you have a bit of time, I’d drop some
console.logon everything in https://github.com/ojkelly/yarn.build/blob/f0bace2ef13d0e36cf54a739c43db3b76cd4fcf8/packages/plugins/plugin-bundle/src/commands/bundle/index.ts#L228.And see what it’s getting tripped up on.
Again, that functions job is just to reduce the bundle size.
Also see there’s two uses of
removeExcluded, the first is for each package which doesn’t clear empty dirs, and the second is for the global excluded list which does clear empty dirs https://github.com/ojkelly/yarn.build/blob/f0bace2ef13d0e36cf54a739c43db3b76cd4fcf8/packages/plugins/plugin-bundle/src/commands/bundle/index.ts#L542Can you expand on this? is it just like the
packages/**/package/node_modulesor something in the topnode_modules?We run yarn install before reducing the bundle size to let yarn itself remove any unused dependencies (of which there may be some, as we have removed your other local packages that are needed).
I feel like we’re finally getting closer to resolving this bug.