3

I have a file x.js which works fine on it's own.

function test() {
    console.log("test");
}

I want to include this into truffle, so I do the following

truffle(development)> exec ./x.js
Using network 'development'.

TypeError: fn is not a function
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-require/require.js:128:1

I do not understand the error, how to fix?

Peter Prographo
  • 1,141
  • 1
  • 10
  • 27

1 Answers1

5

Truffle requires your script to export a function. Try something like this:

module.exports = function(callback) {
    console.log("test");
    callback();
}

And check out the docs: https://www.trufflesuite.com/docs/truffle/getting-started/writing-external-scripts

newbyca
  • 1,523
  • 2
  • 13
  • 25