1

I am trying to follow the truffle pet shop tutorial and I am doing my first truffle migration.

After this command:

truffle migrate

I get this error:

SyntaxError: Invalid or unexpected token at new Script (vm.js:74:7) at Object.createScript (vm.js:246:10) at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-require/require.js:96:1 at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

I tried installing the latest truffle, deleting the contract/build folder and compile again, changing the pragma solidity ^0.4.17; to pragma solidity ^0.4.24; to make Adoption.sol pragma version to be consistent with the one on Migrations.sol

Anyone solved this error before?

2
  • What is the content of your migrations scripts? Can you add the whole output of the truffle migrate command?
    – Ismael
    Aug 16, 2018 at 1:03
  • 1
    (Solved) It was like this: 2_deploy_contracts.js. var Adoption = artifacts.require("Adoption"); module.exports = function(deployer) { deployer.deploy(Adoption); }; // It worked when I deleted the name of the file - on the file
    – Maruta
    Aug 16, 2018 at 1:31

4 Answers 4

1

Solved, the problem that when I named the migrations file as 2_deploy_contracts.js, the name was placed on the file itself. Once I deleted this line, it worked

2
  • I am having the same problem. What do you mean by "the name was placed on the file itself"? do you mean it was within the code in the file or the title of the file?
    – Zakoff
    May 21, 2019 at 19:48
  • 1
    it was in the code in the file
    – Maruta
    May 23, 2019 at 7:34
1

Same problem here when I was following the tutorial of Dapp University. Deleted the 2_deploy_contracts.js file and it works.

1
  • 1
    It is more common to make your modifications in 2_deploy_contracts.js and leave the script 1_initial_migration.js alone. But it should work if you modify only one and delete the other.
    – Ismael
    Oct 21, 2018 at 22:08
0

Just delete the 2_deploy_contracts.js file and edit the 1_initial_migration.js.

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

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

I had the same problem. I have resolved it by changing the encoding from UTF-16LE to UTF-8

Error:

enter image description here

After adding the following solution, it starts working fine for me

enter image description here

If you are using VSCode then you can change Encoding by using the following:

1) Change encoding, choose the option "Reopen with Encoding"

2) And if you see weird character then type CTRL+Z and save the file

3) Run the command and you are done.

enter image description here

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.