Truffle's artifact is undefined when running truffle migrate

Viewed 681

I'm trying to run truffle migrate on two js files: 1_initial_migration.js and 2_deploy_contracts.js. I can successfully compile my .sol files to .json ABIs but then when I try to migrate I get the following error:

const Migrations = artifacts.require("Migrations");
                             ^

TypeError: Cannot read property 'require' of undefined

Here's how I've utilised artifacts in my js files:

const { artifacts } = require("truffle");
const Migrations = artifacts.require("Migrations");

truffle version results are as follows:

Truffle v5.1.39 (core: 5.1.39)
Solidity v0.5.16 (solc-js)
Node v14.16.0
Web3.js v1.2.1

Also I'm following this course on youtube.

I've seen a couple of posts about changing solitidy version, solc(?) version, and truffle version. I've tried downgrading my global truffle version to 5.1.39 and upgrading the solidity version at the start of my .sol files to ^0.6.0, as that seems to be the recommendations from those posts:

https://ethereum.stackexchange.com/questions/84388/solidity-0-6-0-truffle-compile-error-cannot-read-property-of-undefined

https://github.com/trufflesuite/truffle/issues/4191

2 Answers

Try these files:

1_initial_migration.js:

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

2_deploy_contracts.js:

const YourContractName = artifacts.require("YourContractName");

module.exports = function(deployer) {
  deployer.deploy(YourContractName);
};

Don't do anything just update the truffle Your error will be removed

Related