https://github.com/DualWield/nuxt-test
// 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();
No error occured
Cannot assign to read only property 'exports' of object '#<Object>'
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(坑)