0

I'm getting an error while running node compile.js

The error is as follow;

C:\Users\PC\HealthcareDPL\compile.js:30
].HealthcareDPL;
 ^

TypeError: Cannot read properties of undefined (reading 'HealthcareDPL')
    at Object.<anonymous> (C:\Users\PC\HealthcareDPL\compile.js:30:2)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\PC\HealthcareDPL\deploy.js:3:22)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Kindly help me with this issue.

My code for compile.js file is below:

const path = require("path");
const fs = require("fs");
const solc = require("solc");

const healthcarepath = path.resolve(
  __dirname,
  "contracts",
  "healthcaredpl.sol"
);
const source = fs.readFileSync(healthcarepath, "utf8");

const input = {
  language: "Solidity",
  sources: {
    "healthcaredpl.sol": {
      content: source,
    },
  },
  settings: {
    outputSelection: {
      "*": {
        "*": ["*"],
      },
    },
  },
};

module.exports = JSON.parse(solc.compile(JSON.stringify(input))).contracts[
  ":healthcaredpl.sol"
].HealthcareDPL;

console.log(JSON.parse(solc.compile(JSON.stringify(input))).contracts);
2
  • Can you post your compile.js
    – immaxkent
    Dec 13, 2022 at 10:46
  • Sure, I've edited the question. You can see it there. Dec 13, 2022 at 10:53

1 Answer 1

0

The error TypeError: Cannot read properties of undefined (reading 'HealthcareDPL') at Object. is the clue.

I'm unsure of the structure of the parsed solc.compile... etc... but it looks like you are trying to access the array contracts by passing a string value [ ":healthcaredpl.sol" ], which cannot happen in javascript.

I would remove the HealthcareDPL, and console.log(module.exports) to ascertain how this value is actually accessible.

3
  • XaEk I got this issue after updating npm modules to the latest version @9.2.0. Before this update, all the files were running properly. Dec 15, 2022 at 7:45
  • have you updated your dependencies in your package.json ?
    – immaxkent
    Dec 15, 2022 at 10:51
  • Yes, all of the dependencies which are present in the package.json file are updated according to the latest version. Please let me know that node modules are not present in package.json file, should I add it in it for the latest version? Dec 16, 2022 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.