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

Gulp 5 - Copied images using .src and .dest are corrupt #2777

Closed
4 tasks done
rickdoesburg opened this issue Apr 4, 2024 · 4 comments
Closed
4 tasks done

Gulp 5 - Copied images using .src and .dest are corrupt #2777

rickdoesburg opened this issue Apr 4, 2024 · 4 comments

Comments

@rickdoesburg
Copy link

rickdoesburg commented Apr 4, 2024

Before you open this issue, please complete the following tasks:

  • use the search bar at the top of the page to search this repository for similar issues or discussions that have already been opened.
  • if you are looking for help from the gulp team or community, open a discussion.
  • if you think there is a problem with the plugin you're using, open a discussion.
  • if you think there is a bug in our code, open this issue.

What were you expecting to happen?

I except files to be copied to my dist folder

What actually happened?

The files are copied, but the images are corrupt and unreadable. Tried both .jpeg and .webp

Please give us a sample of your gulpfile

const gulp = require("gulp");

// Copy assets to dist
gulp.task("copy", () => {
    return gulp.src(["./assets/**/*"], { base: "./assets/" }).pipe(gulp.dest("./dist/"));
});

// Default task
gulp.task("default", gulp.parallel("copy"));

Terminal output / screenshots

~/Projects/gulp-5-copy-demo » gulp copy 
[09:29:35] Using gulpfile ~/Projects/gulp-5-copy-demo/gulpfile.js
[09:29:35] Starting 'copy'...
[09:29:35] Finished 'copy' after 90 ms

Please provide the following information:

  • OS & version [e.g. MacOS Catalina 10.15.4]: 14.4.1 (23E224)
  • node version (run node -v): v20.8.0
  • npm version (run npm -v): 10.1.0
  • gulp version (run gulp -v): 5.0.0 / CLI 3.0.0

Additional information

Running this command on gulp4 causes no issues. After updating to gulp 5 the images are still copied but are corrupt.

@Patta
Copy link

Patta commented Apr 4, 2024

Try to set { encoding: false } option to src. See "Stream encoding" at https://medium.com/gulpjs/announcing-gulp-v5-c67d077dbdb7

@rickdoesburg
Copy link
Author

My apologies, skipped over that part. Setting encoding to false fixes the issue.

@yocontra
Copy link
Member

yocontra commented Apr 6, 2024

Docs have been updated: https://github.com/gulpjs/gulp/blob/master/docs/api/src.md#options

You need to add { encoding: false } for binary files.

@iamontheinet
Copy link

I have the same issue where the images (.png) are in the right location but they're corrupt in that they won't even open in Preview. And I've tried setting encoding: false as shown below but that didn't work.

gulp.task('build:images', () => {
  const srcs = [
    'app/images/**/*',
    'app/favicon.ico',
  ];

  return gulp.src(srcs, { base: 'app/', encoding: false })
    .pipe(gulp.dest('build'));
});

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

No branches or pull requests

5 participants