Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

645
Visualizações
ReferenceError: require is not defined in ES module scope, you can use import instead

Here I have mentioned the Files I have used. I have tried in both ways, by adding and removing of "type" : "module" tag in package.json file.

App.js

var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
  fs.readFile('app.html', function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080);

import { hello } from './sell.js';
hello();


app.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>React JS </title>
</head>
<body>
<h1>JavaScript Tutorial</h1>

<script type="module" src="app.js"></script>
</body>
</html>

sell.js

export let hello = () => {
    console.log("heyy shreya suman");
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Look, there are 2 ways to import somthing

  1. var http = require('http');
  2. import http from "http"

But you cant use import and require() at the same time, it does not work. You either use require() or import And, your package.json module type or file extension must match the type of import you are using

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda