0

Why does truffle compile report TypeError: Cannot destructure property 'contractName' of 'contract' as it is undefined?

$ npx truffle compile --all

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/coins/CoinToken.sol
> Artifacts written to /home/james/workspace/rustedsolid/build/contracts
> Compiled successfully using:
   - solc: 0.6.12+commit.27d51765.Emscripten.clang
TypeError: Cannot destructure property 'contractName' of 'contract' as it is undefined.
    at forContract (/home/james/workspace/rustedsolid/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/shims/NewToLegacy.js:5:13)
    at Array.map (<anonymous>)
    at Object.save (/home/james/workspace/rustedsolid/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:123:1)
    at Object.module.exports [as run] (/home/james/workspace/rustedsolid/node_modules/truffle/build/webpack:/packages/core/lib/commands/compile/run.js:38:1)
    at Command.run (/home/james/workspace/rustedsolid/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.5.3 (core: 5.5.3)
Node v16.13.2

1 Answer 1

1

Changing truffle-config.js from this:

module.exports = {
    compilers: {
        solc: {
            version: "pragma",
            settings: {
                optimizer: {
                    enabled: true,
                    runs: 200
                },
            }
        }
    },
};

To this - just changing the "pragma" to specify a compiler version:

module.exports = {
    compilers: {
        solc: {
            version: "0.6.12",
            settings: {
                optimizer: {
                    enabled: true,
                    runs: 200
                },
            }
        }
    },
};

Makes the problem go away.

2
  • 1
    But I need my version to be pragma so I can support multiple solidity versions. 🤔
    – BananaNeil
    Commented Oct 19, 2022 at 16:31
  • Switch to hardhat? That's what we did quite a while ago. Commented Oct 20, 2022 at 18:07

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.