'the require function doesnt works and i tried node.js and it still doesnt works [duplicate]
So when i launched my website it tells that the require function isnt recognized i think that its cause its a node.js function but when i tried it always tell the same thing
const chien = {
nom:'Louis',
couleur:'Bronze',
race:'Stupide'
}
const fs = require('fs')
const saveData = (chien) =>{
const finished = (error) =>{
if (error){
console.error(error)
return;
}
}
const jsonData = JSON.stringify(chien)
fs.writeFile('louisverite.json',jsonData,finished)
}
saveData(chien)
Solution 1:[1]
go to package.json file and change
type: "module"
to
type: "commonjs"
This is because in package.json if we define type as module its uses the es6 js which has import statement and if we make it to commonjs it will use es5 which has require funcion
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
