Home

Issue: 3204

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

[issue link]

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 ‘#

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(坑)

This bug report is available on Nuxt.js community (#c6868)