travis-r6s / gridsome-plugin-brotli

Gridsome plugin for preparing brotli-compressed versions of assets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON compression fails for empty/missing index.vue data property

jason7sc opened this issue · comments

Awesome plugin! Thanks for taking the time to put it together.

I was working on a site and had an issue come up while building. Perhaps others have ran into it as well.

It appears that when the index.vue page is missing a data property, or the data property returned by a function is empty, the compression fails for JSON files (dist/assets/data).

Here is the error output:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received null
    at writeFile (fs.js:1356:5)
    at internal/util.js:297:30
    at new Promise (<anonymous>)
    at writeFile (internal/util.js:296:12)
    at compressFile (/path/to/my/site/node_modules/gridsome-plugin-brotli/worker.js:24:9)

Sample index.vue that causes the error:

<template>
    <h1>Home</h1>
</template>

<script>
    export default {
        metaInfo: {
            title: 'Home'
        },
        data(){
            return {}
        }
    }
</script>

Outputted JSON file that fails compression (dist/assets/data/index.json):

{"hash":"a38dd2e542c0e62025c3d51f01861b88ab2a01d2","data":null,"context":{}}

Strangely, even with an empty, defined data property, the outputted JSON file is identical.

// template from previous example still applies
<script>
    export default {
        metaInfo: {
            title: 'Home'
        },
        data: {}
    }
</script>

Outputted JSON that successfully compresses (dist/assets/data/index.json):

{"hash":"4a3972e9372535a0402b06f00b5337886e621d75","data":null,"context":{}}

Any ideas on the cause of this? It's easy to add a data property to the vue file and move on, but this may catch others off-guard, like it did to me.

Hey @jason7sc - thanks for the comprehensive report. I have had a similar issue recently on some sites, so will look further into it...