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.

`yarn bundle` throwing error `ENOENT: no such file or directory`

See original GitHub issue

Describe 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:

  1. Checkout this repo on branch amarok: https://github.com/connext/nxtp/tree/amarok
  2. Run yarn bundle in packages/agents/sequencer
  3. See error

Expected behavior Bundle happens.

Screenshots Screen Shot 2022-03-14 at 10 57 37

Desktop (please complete the following information):

  • OS: macOS

Additional context Yarn version: 3.2.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ojkellycommented, Apr 19, 2022

Nothing prevents copying all the files at the moment, as we’re using an os file copy to setup the tmp dir.

.bundleignore prevents 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 --exclude folders, and subtract them from a list of files to copy instead of taking a full copy of the whole repo.

0reactions
ojkellycommented, Nov 13, 2022

My only concern, again it’s your code, that if you do that it might break (or not) the integrity of the operation:

Yep fair. In this case the only point of that function removeEmptyDirectories is 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.

On Windows, when traversing directories to delete empty directories, the bundle command incorrectly joined paths with path.join when ppath.join should have been used. As a result, the removeEmptyDirectories recursed into invalid paths and the check for whether the invalid path is a directory failed due to ENOENT: no such file or directory.

It’s preferable for the bundle to be marginally bigger, than break in some circumstances.

why is it attempting to delete something that doesn’t exist

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.log on 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#L542

in my case I think it was a symbolic link pointing to my workspace packages.

Can you expand on this? is it just like the packages/**/package/node_modules or something in the top node_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.

Read more comments on GitHub >

github_iconTop 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 >

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