Autotask Local Development

I am trying to run my autotask script locally and I can't seem to get it to run. I've added the necessary code to the bottom of my autotask to run locally, and I can confirm my API keys work (I can programmatically upload autotask files).

My code export.handler function just stops when it has to run:

    const provider = new DefenderRelayProvider(credentials)
    const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fast' })

I'm thinking the issue comes with the package dependencies. I use npm. I grabbed the yarn.lock file and then ran:

yarn install

A laundry list of warning's popped up (see below). I am not sure which ones are of concern and which ones are not. My directory has a package-lock file (as seen in the first warning). I am not sure if this is block anything or not. I also noticed at the end there were unmet peer dependencies for defender-relay-client which seems like an issue.

Any suggestions on how to fix this issue?

warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
warning aws-sdk > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning aws-sdk > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning ethereum-waffle > @ethereum-waffle/compiler > @resolver-engine/imports > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-common@1.5.0: New package name format for new versions: @ethereumjs/common. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-account@3.0.0: Please use Util.Account class found on package ethereumjs-util@^7.0.6 https://github.com/ethereumjs/ethereumjs-util/releases/tag/v7.0.6
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-tx@2.1.2: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm@4.2.0: New package name format for new versions: @ethereumjs/vm. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-account@3.0.0: Please use Util.Account class found on package ethereumjs-util@^7.0.6 https://github.com/ethereumjs/ethereumjs-util/releases/tag/v7.0.6
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-tx@2.1.2: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-block > ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-vm > ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > ethereumjs-vm > ethereumjs-common@1.5.2: New package name format for new versions: @ethereumjs/common. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > @ethereum-waffle/ens > @ensdomains/ens@0.4.5: Please use @ensdomains/ens-contracts
warning ethereum-waffle > @ethereum-waffle/compiler > @resolver-engine/imports > @resolver-engine/core > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-blockchain@4.0.4: New package name format for new versions: @ethereumjs/blockchain. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-blockchain > ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-block-tracker > ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > @ethereum-waffle/ens > @ensdomains/resolver@0.2.4: Please use @ensdomains/ens-contracts
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > ethereumjs-vm > ethereumjs-blockchain > ethashjs@0.0.8: New package name format for new versions: @ethereumjs/ethash. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > @ethereum-waffle/ens > @ensdomains/ens > testrpc@0.0.1: testrpc has been renamed to ganache-cli, please use this package from now on.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-block-tracker > json-rpc-engine > safe-event-emitter@1.0.1: Renamed to @metamask/safe-event-emitter
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > eth-tx-summary > ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > eth-tx-summary > ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-json-rpc-infura > eth-json-rpc-middleware > eth-tx-summary > ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > patch-package > find-yarn-workspace-root > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-block-tracker > json-rpc-engine > babelify > babel-core > babel-register > core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning ethereum-waffle > @ethereum-waffle/provider > ganache-core > web3-provider-engine > eth-block-tracker > json-rpc-engine > babelify > babel-core > babel-runtime > core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
warning hardhat > mocha > debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
warning hardhat > mocha > chokidar > fsevents@2.1.3: "Please update to latest v2.3 or v2.2"
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > defender-relay-client@1.10.0" has unmet peer dependency "@ethersproject/abstract-provider@^5.0.2".
warning " > defender-relay-client@1.10.0" has unmet peer dependency "@ethersproject/abstract-signer@^5.0.2".
warning " > defender-relay-client@1.10.0" has unmet peer dependency "@ethersproject/providers@^5.0.5".
warning " > defender-relay-client@1.10.0" has unmet peer dependency "web3-core@^1.3.4".
warning " > defender-relay-client@1.10.0" has unmet peer dependency "web3-core-helpers@^1.3.4".
warning "ethereum-waffle > @ethereum-waffle/compiler > typechain > ts-essentials@6.0.7" has unmet peer dependency "typescript@>=3.7.0".
[4/4] 🔨  Building fresh packages...
success Saved lockfile.

There are a couple things going on here:

First, when adding the 'run locally' code for autotask, I needed to add the below package to grab the api key & secret to get it to work.

require('dotenv').config()

I did found a couple GOTCHA's:

The term API_KEY and API_SECRET for running the autotask code locally is referring to the Relayer key/secret.

Elsewhere, in order to upload autotasks programmatically, you use the same terms API_KEY and API_SECRET names in your .env to upload autotasks into OZ.

The problem seems to be that the API for uploading autotask code is using the Team API Key, where as the API to run code locally is using the Relayer API but they are mapped the same.

Autotask also does NOT like the dotenv package being uploaded to the autotask in OZ defender. Is there an elegant work around for this so I can seemlessly work locally and upload to OZ defender, or do I have to hardcode the keys to my environmental variables of my computer?

Hey @Guceri! What I usually do to work around this is require dotenv only when the code is run locally. See this example:

Alternatively, you can place the entrypoint on a different file that requires both dotenv and the autotask script. You use that file for running locally, but never execute it when uploaded to the autotask.

Thanks @spalladino ,
I tried moving the require('dotenv').config(); into the if statement a couple days ago and it didn't work. I tried again just incase it was a user error and it still produces an error when I trigger my autotask:

Error: Cannot find module 'dotenv'

The error originates from this line in my index.js file which is what webpack created :

Object(function webpackMissingModule() { var e = new Error("Cannot find module 'dotenv'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).config()

this is because in the webpack.config.js file there is the following:

  plugins: [
    // List here all dependencies that are not run in the Autotask environment
    new webpack.IgnorePlugin({ resourceRegExp: /dotenv/ }),
  ],

My next step was to just ignore the require statement and upload the file into the autotask to run again. This time I got an error as follows:

Error: Runtime exited without providing a reason

I think the reason here is because it does not like this line of code:

const { API_KEY: apiKey, API_SECRET: apiSecret } = process.env;

If I ignore the entire require.main === module if statement then the code runs fine. As a test, I also just inserted console.log('This was triggered....') into the if statement and it was logged in the autotask:

Logs
AUTOTASK START
2021-08-04T18:37:16.675Z	undefined	INFO	This was triggered....

Is the conclusion I am drawing here correct that the require.main === module is running and not being ignored by the autotask?

I've just double-checked it on an Autotask, and I see it being ignored. I'll see if I can find any scenario where this could be invoked, but in the meantime, if this is causing issues, I'd suggest you then remove that piece of code from the file that gets uploaded and move it to a separate file in your local setup that runs the require('dotenv').config() and then requires the autotask code and runs it.

No worries. It does seem odd that it doesn't work.

I do upload my bundled index.js programmatically. i wouldn't expect that to be a problem, but thought I would mention it.

It is the same autotask ID I sent to support of it helps to directly look at it.