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:

Solidity ^0.6.0 Truffle Compile Error: Cannot read property ... of undefined


2 Answers 2


If you are using Vs-Code, the editor might give an error that artifact is not defined if you remove this line:

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

But if you run truffle compile, the contract will compile successfully as the artifact is globally available since you have installed truffle globally in your system.

Just add // eslint-disable-next-line no-undef to remove that error and it will work.


Ammar's solution works for me, thanks a lot


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


// eslint-disable-next-line no-undef

and migrated successfully

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.