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);