# Failed to read zip file

**URL:** <https://forum.ghost.org/t/failed-to-read-zip-file/8325>\
**Category:** Themes\
**Created:** [July 19, 2019, 3:00am UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325 "2019-07-19T03:00:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SylarRuby](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sylarruby/32/1704_2.png) [@SylarRuby](https://forum.ghost.org/u/SylarRuby)\
**Post date:** [July 19, 2019, 3:00am UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/1 "2019-07-19T03:00:31Z")

</div>

On local machine, I’ve made changes to the casper theme. I then used the download button to download the theme. In production, I use the upload button, selected downloaded theme then upload… then got “Failed to read zip file”

 ![48](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/2X/7/7352b0b0f9430381ee04310c847cfde2f9cabdb9.png)

Form Data:

```
Content-Disposition: form-data; name="file"; filename="mayneweb.zip"
Content-Type: application/zip

```

After the message, I got a status code of `422` 🤷🏽‍♂️

This server is a one-click install using DO. I’ve recently upgraded to 2.25.8 (on both dev and prod) using:

`ghost upgrade 2.25.8`

Local machines cannot upload the same file it downloaded either 😢

---

<div class="post-metadata">

**Author:** ![SylarRuby](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sylarruby/32/1704_2.png) [@SylarRuby](https://forum.ghost.org/u/SylarRuby)\
**Post date:** [July 19, 2019, 3:22am UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/2 "2019-07-19T03:22:04Z")

</div>

Think I got it. I needed to run `gulp zip` 🤗 as per `package.json`

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [July 19, 2019, 8:45am UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/3 "2019-07-19T08:45:43Z")

</div>

> [@SylarRuby](#):
>
> I then used the download button to download the theme. In production, I use the upload button, selected downloaded theme then upload… then got “Failed to read zip file”

This process should work 🤔 Do you see any more specific error messages in your log files?

---

<div class="post-metadata">

**Author:** ![SylarRuby](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/sylarruby/32/1704_2.png) [@SylarRuby](https://forum.ghost.org/u/SylarRuby)\
**Post date:** [July 19, 2019, 3:12pm UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/4 "2019-07-19T15:12:58Z")

</div>

Yes.

> ERROR DETAILS:  
> “EINVAL: invalid argument, symlink ‘’ → ‘/private/var/folders/zx/g\_znzp193x76zdb8ppjgvd\_w0000gn/T/ab72decc-cc39-4b21-81dd-94ad1ea27980/node\_modules/gscan/test/fixtures/themes/030-assets/symlink2/assets/mysymlink’”

 ![47](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/2X/e/ebc0197558ec7d02f6734cf596b7999310051bd6.png)

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [July 19, 2019, 3:54pm UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/5 "2019-07-19T15:54:05Z")

</div>

Thanks! That suggests that we should be skipping the `node_modules` directory if it exists when creating a zip on the server. I’ll open an issue.

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [July 19, 2019, 4:16pm UTC](https://forum.ghost.org/t/failed-to-read-zip-file/8325/6 "2019-07-19T16:16:24Z")

</div>

Issue opened here. This should be a fairly self-contained and small task good for anyone new to the codebase if someone fancies tackling it 😄

> <https://github.com/TryGhost/Ghost/issues/10929>
>
> \### Issue Summary
> 
> When performing local development of a theme it can be usef…ul to click the "download" button for the theme in the admin area to get a zip in order to upload it. However, if you have any node modules installed in the theme then they can get bundled up, creating a \_huge\_ zip file and potentially breaking the theme import.
> 
> This issue was originally reported on the forum here https://forum.ghost.org/t/failed-to-read-zip-file/8325
> 
> \### To Reproduce
> 
> 1. \`cd\` into the \`content/themes\` directory and run \`cp -R casper casper-custom\`
> 2. \`cd casper-custom\` then run \`yarn\`
> 3. start Ghost
> 4. navigation to the Design screen in the admin area
> 5. click the "download" link for the custom casper theme to get a zip
> 6. click "Upload a theme" and attempt to upload the zip file
> 7. note the error messages in your server logs
> 
> The upload is failing because the \`node\_modules\` directory is included in the zip and Casper uses the \`gscan\` module which has an intentionally bad symlink in it's test files to ensure that theme uploads fail on bad symlinks.
> 
> Although it's not always the \_correct\_ way of creating a zip file for a local theme (it won't run any build steps for example) the above flow is still useful in many circumstances. We should ensure that the \`node\_modules\` directory is skipped when creating a zip to fix the flow and to reduce server load from attempting to zip potentially thousands of module files.
> 
> \### Potential Solution
> 
> For reference, zip files creation is \[triggered in ThemeStorage class\](https://github.com/TryGhost/Ghost/blob/master/core/frontend/services/themes/ThemeStorage.js#L38) and uses the \[zip-folder utility\](https://github.com/TryGhost/Ghost/blob/master/core/server/lib/fs/zip-folder.js) which in turn uses the external \[archiver\](https://www.npmjs.com/package/archiver) module.
> 
> A potential solution could be performing some file globbing (Ghost already has the \[glob\](https://github.com/isaacs/node-glob) dependency) to generate a file list excluding the \`node\_modules\` directory which can then be passed to the \`archiver\` instance.
