Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(copy plugin) Error: ENOENT: no such file or directory, chmod <filename> #61

Open
HanMoeHtet opened this issue Jan 4, 2022 · 7 comments · May be fixed by #71
Open

(copy plugin) Error: ENOENT: no such file or directory, chmod <filename> #61

HanMoeHtet opened this issue Jan 4, 2022 · 7 comments · May be fixed by #71

Comments

@HanMoeHtet
Copy link

Why is it throwing ENOENT when a file in dist does not exist? Isn't the purpose of this plugin to copy files into dist? The action is not even predictable. It only happens sometimes. However, files are indeed copied into dist but in CI, it always fails because of exit code 1.

@gunnartorfis
Copy link

Happening to me as well. Any ideas for a workaround?
In my case, I'm copying JSON localization files over to the dist folder after a build.

@HanMoeHtet
Copy link
Author

@gunnartorfis I just copied the source and tweaked a little. Just added try catch block Here

@allista
Copy link

allista commented Aug 4, 2022

Same here. For some reason it fails to chmod a copied file.

And for me it fails sporadically, without any pattern, which suggests a race condition.

I have "rollup-plugin-copy": "3.4.0"

@DanielOrtel
Copy link

DanielOrtel commented Sep 1, 2023

are you by chance using del, or any plugin that cleans the output directory? I started seeing the error when I added that. One solution would be to ensure that copy runs after del, and that both use the same buildEnd hook:

    del({
      targets: ['./.dist', './public'],
      hook: 'buildEnd',
      runOnce: true
    }),
    copy({
      targets: [{ src: 'prebuilt/*', dest: 'public/' }],
      hook: 'writeBundle',
      copyOnce: true
    })

If that doesn't work, fork the package and add:

if (!fs.existsSync(path.dirname(dest))) {
    fs.mkdirSync(path.dirname(dest), { recursive: true });
}

before the copy, to ensure that the directory is created before attempting to copy it. Fyi, that should solve any issues with this package.

@DanielOrtel DanielOrtel linked a pull request Sep 1, 2023 that will close this issue
@vladshcherbin
Copy link
Owner

Can someone provide a reproduction repo? I'll try to find the underlying reason 🙌

@DanielOrtel
Copy link

DanielOrtel commented Sep 2, 2023

I can provide one, though I'm currently using the fork I created(see the linked PR above), and I haven't seen this issue since.

Basically add this to any package's rollup config:

const del = require('rollup-plugin-delete');

export const config = {
    input: './index.js',
    output: {
      sourcemap: true,
      dir: './.dist',
      format: 'esm'
    },
      copy({
        targets: [{ src: 'prebuilt/*', dest: 'public/' }],
        copyOnce: true
      }),
      del({
        targets: ['./.dist', './public'],
        hook: 'buildEnd',
        runOnce: true
      })
}

And ensure there is something in the prebuilt folder to copy. I believe it should fail, because the folder does not exist, since the del hook removed it.

If you need a full repro, I can also provide a repo for that, though again, #71 fixes this issue for me.

@vladshcherbin
Copy link
Owner

@DanielOrtel thank you, will try locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants