Static GitHub Issues

[3204] When using commonJS Module and JSON.stringify together, an error occured: Cannot assign to read only property 'exports' of object '#<Object>'

prev: After using router.push\replace asyncData not called on new page
next: svg can't be used in nuxt.js

Version

v1.4.0

Reproduction link

https://github.com/DualWield/nuxt-test

Steps to reproduce

// logger.js

JSON.stringify({name: 'test'})

module.exports = {
    info() {
        console.log('info');
    },
    error() {
        console.log('error');
    }
}

// page/index.vue const logger = require('./logger'); logger.info();

What is expected ?

No error occured

What is actually happening?

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

Additional comments?

I know this error happened because mixing import and module.exports. But why I remove JSON.stringify , it works ? I want the logger.js is commonjs module style, because this file is both required in client and node server. And I don't want to use webpack to compile the node file. such a big pit(坑)

<!--cmty--><div align="right"><sub><em>This bug report is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c6868">#c6868</a>)</em></sub></div>