0

The tutorial I'm following created a 2_Migrations.sol with the following:

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

module exports = function(deployer) { 
  deployer deploy(Token);
}; 

"Truffle Migrate" gave this error:

e:\GitHub\NealWalters\DappUniversity\blockchain-developer-bootcamp>truffle migrate

Compiling your contracts...
===========================
> Compiling .\src\contracts\1_Migrations.sol
> Compiling .\src\contracts\2_Migrations.sol
> Compiling .\src\contracts\Token.sol

Error: CompileError: /e/GitHub/NealWalters/DappUniversity/blockchain-developer-bootcamp/src/contracts/2_Migrations.sol:3:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
const Token = artifacts.require("Token");
^---^

Compilation failed. See above.
    at Object.compile (C:\Users\nwalt\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\legacy\index.js:72:1)
Truffle v5.0.40 (core: 5.0.40)
Node v10.16.2

If I add the same Pragma that is in 1_migrations.sol (the file generated by truffle init" and renamed):

pragma solidity >=0.4.21 <0.6.0;

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

module exports = function(deployer) { 
  deployer deploy(Token);
}; 

I get the same error.

If I try the same pragma as my Token contract:

pragma solidity ^0.5.0;

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

module exports = function(deployer) { 
  deployer deploy(Token);
}; 

Also gives same error.

truffle-config.js contains this for the compiler settings:

  compilers: {
    solc: {
      optimizer: {
        enabled: true,
        runs: 200
      }
   }

1 Answer 1

1

It is trying to compile migrations scripts as solidity code. That will not work.

Move migrations scripts to the directory migrations and rename them with the .js extension.

Your project should look like this

migrations\
     1_Migrations.js
     2_Migrations.js

contracts\
     Token.sol
1
  • Thanks you, correct. I noticed that about the same time you posted. Works now! And 2_Migrations is .js suffix, not .sol suffix. Oct 13, 2019 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.