I am trying to include the following as protobuf/index.js
const protobuf = require('protobufjs')
const root = protobuf.Root.fromJSON(require('./protobuf_bundle.json'))
const Message = root.lookup('Message')
Message.MessageType = Message.nested.MessageType.values
Message.MessageType.stringValue = (id) =>
`${Message.nested.MessageType.valuesById[id]}(${id})`
let exportableMessages =
Object.keys(root)
.filter((key) => /^[A-Z]/.test(key))
.reduce((acc, key) => {
acc[key] = root[key]
return acc
}, {})
// Add our stringValue enabled Message
exportableMessages['Message'] = Message
module.exports = exportableMessages
However when I include this into any other file by using
import protobuf from '../protobuf'
I get
TypeError: "exports" is read-only
I can't see anything glaringly obvious, nor can I fathom what it could be if it isn't this.