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
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.truffle migrate --reset --config truffle-config.cjs pero arrojó el mismo error que en 1.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" }