Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Importe variables y funciones desde un archivo js a un archivo de migración y un archivo de prueba con trufa

Tengo un archivo en la carpeta de mi proyecto llamado `helpfulSuff.js` donde tengo variables y funciones globales que me gustaría usar tanto en mis archivos de migración como en mis archivos de prueba.
  1. Sin embargo, cuando intento importar las variables a los archivos de migración, aparece el siguiente error al intentar migrar el contrato: SyntaxError: Cannot use import statement outside a module

  2. Después de haber agregado "type": "module" a mi package.json , ejecutar truffle migrate --reset da el siguiente error:

 Error [ERR_REQUIRE_ESM]: require() of ES Module /home/nic/Documents/blockchain/kittyFinance/truffle-config.js from /usr/local/lib/node_modules/truffle/node_modules/original-require/index.js not supported. truffle-config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
  1. Luego intenté ejecutar truffle migrate --reset --config truffle-config.cjs pero arrojó el mismo error que en 1.
  2. Finalmente traté de modificar el tipo en mi package.json a commonjs y ejecuté truffle migrate --reset pero me dio el error mencionado en 1. otra vez

¡Gracias por tu ayuda!

Mis archivos actuales:

  • ./helpfulSuff.js
 const tokenConstants { NAME: "Kitty Finance", SYMBOL: "KTFN", INITIAL_SUPPLY: 10000000 }; export { tokenConstants };
  • ./migrations/2_deploy_contracts.js
 const Token = artifacts.require("Token"); import { tokenConstants } from '../helpful_stuff'; /*const name = "Kitty Finance"; const symbol = "KTFN"; const initialTokenSupply = 10000000; // 10 million tokens initial supply*/ var token; module.exports = function (deployer, network, accounts) { if (network == "development") { return deployer.deploy( Token, tokenConstants.NAME, tokenConstants.SYMBOL, tokenConstants.INITIAL_SUPPLY, { from: accounts[0] }) .then(function(instance) { token = instance; }) } };
  • ./package.json
 { "dependencies": { "@openzeppelin/contracts": "^4.5.0", "@truffle/hdwallet-provider": "^2.0.4", "dotenv": "^16.0.0" }, "type": "commonjs" }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!