I'm new to javascript and I am following a Nuxt tutorial where I created the app skeleton with npx create-nuxt-app
. The tutorial got me up and running with a basic frontend. Now I need to add the module commonjs
to my project (to resolve Error: exports is read-only when I try to require
modules from a nodejs backend).
I was told I could add commonjs to babel.config.js as shown below. However, my Nuxt project does not have babel.config.js.
module.exports = {
presets: [
['@vue/app', {"modules": "commonjs"}]
]
}
I tried adding commonjs
to the modules array in nuxt.config.js and that results in new errors, so I removed it. (After reading the Nuxt docs, I see that the modules section is for Nuxt.js modules.)
How can I add the commonjs module to a Nuxt project created with npx create-nuxt-app?