Oi pessoal Estou com problemas para importar o módulo.Aparece a mensagem abaixo quando jogo para o powershell
PS C:\Users\Suzana\desktop> node .\index.js
(node:14696) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ...
to show where the warning was created)
C:\Users\Suzana\desktop\index.js:1
import {Cliente} from "./Cliente.js"
^^^^^^
SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:355:18) at wrapSafe (node:internal/modules/cjs/loader:1039:15) at Module.compile (node:internal/modules/cjs/loader:1073:27) at Object.Module.extensions..js (node:internal/modules/cjs/loader:1138:10) at Module.load (node:internal/modules/cjs/loader:989:32) at Function.Module.load (node:internal/modules/cjs/loader:829:14) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/runmain:76:12) at node:internal/main/run_main_module:17:47
Index
const cliente1 = new Cliente();
cliente1.nome = "Ricardo";
cliente1.cpf = 1231230006;
cliente2 = new Cliente();
cliente2.nome = "Alice"
cliente2.cpf = 1231230005;
const contaCorrenteRicardo = new contaCorrente();
contaCorrenteRicardo.agencia = 1001;
contaCorrenteRicardo.depositar (-100);
contaCorrenteRicardo.depositar (100);
contaCorrenteRicardo.depositar (100);
const valorSacado = contaCorrenteRicardo.sacar(50);
console.log(valorSacado);
console.log(contaCorrenteRicardo);
Json
{
"name": "bytebank",
"version": "1.0.0",
"description": "Projeto do bytebank para seus clientes",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Rodrigo",
"license": "ISC",
"type": "module"
}
Cliente
export class Cliente{
nome;
cpf;
}
Conta Corrente
export class contaCorrente{
agencia;
_saldo = 0;
sacar(valor){
if(this._saldo >= valor){
this._saldo -=valor;
return valor;
}
}
depositar(valor){
if(valor <= 0){
return;
}
this._saldo += valor;
}
}