avast / vuei18n-po

transform gettext .po files for vue-i18n
BSD 3-Clause "New" or "Revised" License
14 stars 5 forks source link

Cannot assign to read only property 'exports' of object '#<Object>' #4

Closed Heziode closed 4 years ago

Heziode commented 4 years ago

I got this error: Cannot assign to read only property 'exports' of object '#<Object>'.

This is due to plural js generated file, that use the "old node syntax":

module.exports = {
// …
}

I encouter this issue because I use vue-i18n in nuxt (via nuxt-i18n), and to configure the plugin, I use an es6 file. So, you should add the possibility to choose the new syntax, and keep old by default for retro-compatibility (IHMO):

export default {
// …
}
pavelstudeny commented 4 years ago

module.exports and export are normally possible to use together. Is the error above reported by your linter or packager? It should be possible to resolve it by adjusting the settings in their configuration.

Heziode commented 4 years ago

The error is just throw by nuxt when rendering.

I use vue-i18n like this:

// This is the plugin file imported in `nuxt.config.js`
export default () => {
  return {
    locale: "en",
    fallbackLocale: 'en',
    messages: {
      en: require('../lang/en.json'),
    },
    pluralizationRules: require('./vue-i18n-plural.js')
  }
}
pavelstudeny commented 4 years ago

Then it looks like a problem with your packager (rollup?) configuration.

Despite that I could image a --es6 option at cli.js that would alter https://github.com/avast/vuei18n-po/blob/master/index.js#L91 to an ES6 export. I would accept a pull request along these lines and release a new version.

pavelstudeny commented 4 years ago

included in 1.3.0 and available on npmjs. many thanks!