0
I’m trying to make a require on JS but this giving error:
"Uncaught Referenceerror: require is not defined http://127.0.0.1:5500/js/access.js:1"
in access.js I made the following code:
const empresas = require('../api/empresa')
and in the enterprise.js
function empresa(){
return `
const nome = "Nome da empresa";
const logo = "logo.png";
const email = "[email protected]";
`
}
module.exports = empresa
I wanted to do this with pure JS without anything, it’s like what I’m doing wrong?
I found that the error is when I call the index.html page, which I may be doing wrong?
– Ricardo Jardim Braz
you have to import the script type module as a property. <script src="myscript.js" type="module"></script> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/M%C3%B3dulos , in which case you need to use import, export or export default
– Luciano Alves
you can resolve your doubt in this post. https://answall.com/questions/213910/javascript-diff%C3%A7as-entre-import-e-require
– Luciano Alves