Error: Migration ... invalid or does not take any parameters

While doing the I CLONED RARIBLE IN 24H - Token Contract [PART 6] video, I ran into an error during the migration. When I use the command truffle --reset after creating my 2_token_migration file, I get this error:

2_token_migration.js
====================

Error: Migration /Users/devin/Desktop/Productive/contracts/migrations/2_token_migration.js invalid or does not take any parameters
    at Migration._load (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:50:1)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Migration.run (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
    at Object.runMigrations (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.runAll (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
    at Object.run (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
    at runMigrations (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
    at Object.run (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
    at Command.run (/Users/devin/.nvm/versions/node/v16.8.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)
Truffle v5.4.8 (core: 5.4.8)
Node v16.8.0
[email protected] contracts %

Here is the file for my token, ProductiveToken.sol:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";

contract ProductiveToken is ERC721 {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor () ERC721("ProductiveToken", "PROD"){}

    struct Item {
        uint256 id;
        address creator;
        string uri;
    }

    mapping (uint256 => Item) public Items;

    function createItem(string memory uri) public returns (uint256){
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _safeMint(msg.sender, newItemId);

        Items[newItemId] = Item(newItemId, msg.sender, uri);

        return newItemId;
    }

    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

       return Items[tokenId].uri;
    }
}

And here is the file for the migration, 2_token_migration.js:

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

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

Really not sure where I went wrong or whether I am missing something.

Update, in my 2_token_migration.js file, there are three dots underneath the m of the module.exports property.


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

module.exports = function (deployer) {

deployer.deploy(ProductiveToken);

};

When I hover over the module.exports keywords, I get the following “Quick Fix”:

File is a CommonJS module; it may be converted to an ES6 module. ts(80001)

module export=

(property) export=: (deployer: any) => void

Is this the way to go? Should I execute the Quick Fix and run the command truffle migrate --reset again?

PS thank you for the support! I’m just noticing this code posting format and I think its awesome. Will certainly be using a lot more in the future.

Hey @devin

Do you use truffle --reset or truffle migrate --reset?

2_token_migration.js looks fine to me.
Were you able to compile and migrate before or this is the first time you try and you get errors?

Definitely truffle migrate --reset.

This was the first time I tried it, I remember getting a similar error on the first time I tried the tutorial but I didn’t pay attention to it. I’ll try the Quick Fix on the module.exports keyword now.

Update, @cryptokid @Yomoo when I click on the quick fix option, VS code changes my code into this:

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

export default function (deployer) {
  deployer.deploy(ProductiveToken);
};

Any chance this would work? or does it have to be:

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

module.exports = function (deployer) {

deployer.deploy(ProductiveToken);

};

@cryptokid @Yomoo I’m noticing at 2:22 of the tutorial, the Truffle DB config is uncommented, while in my configuration, it is commented. This step is explicit in the tutorial, so could this be the cause of the error?

Update: Never mind, checked the codebase and made the files identical only to get the same result.

@cryptokid @Yomoo I just reached out to truffle and the problem is that my truffle-config.js file isn’t properly configured. Not sure why this is commented out or even mentioned in the tutorial.

1 Like