Truffle '"Migrations" -- cb is not a function' - javascript

I wrote a simple smart contract in Solidity 0.6.6 that I'm trying to deploy to the BSC Testnet.
This is what I have in my truffle-config.js file (privateKeys is an array with a single entry of ['0x + privatekey']:
networks: {
bscTestnet: {
provider: () => new HDWalletProvider(
privateKeys,
'https://data-seed-prebsc-1-s1.binance.org:8545/'
),
network_id: 97,
skipDryRun: true
}
}
When I run the command "truffle migrate --reset --network bscTestnet" I get the following error:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'bscTestnet'
> Network id: 97
> Block gas limit: 30000000 (0x1c9c380)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: *** Deployment Failed ***
"Migrations" -- cb is not a function.
at /Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Migration._deploy (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:70:1)
at Migration._load (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
at Migration.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
at Object.runMigrations (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.runAll (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
at Object.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
at runMigrations (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:80:1)
at Object.module.exports [as run] (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
at Command.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.4.31 (core: 5.4.31)
Node v17.4.0

Opened an Issue a about it: https://github.com/trufflesuite/truffle/issues/4676
I guess its a bug in HardwareWallet2.0.2.
Reverting to HardwareWallet2.0.0 solved the problem for me
npm i #truffle/hdwallet-provider#2.0.0

UPDATE:
Right, workaround: I rolled #HDWalletProvider back to v2.0.1 and was able to migrate.
I assume there must be an issue with the new version for ppl who updated today.
================
Same problem with Polygon Mumbai.
Function "cb" refers to the callback function. The strange part is the error message doesn't reference my own code at all; it references the migrations.js located in:
<.nvm/versions/node/v16.11.1/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at processTicksAndRejections (node:internal/process/task_queues:96:5>
This leads me to believe there's a problem with out 1_initial_migration.js... however that's auto-generated so I can't see any problem... it's strange.
1_initial_migration.js:
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};

Related

child_process.exec tries to launch node (instead of shell command) in some odd circumstances

I am trying to run some simple commands using child_process.exec. But in some odd corner cases, it tries to execute the given command with node, rather than the given (or default) shell.
Results
E.g., given below code, I get the following results:
cmd
Result
❌
'"yarn" -v'
Cannot find module 'C:\cwd\yarn.js'
❌
'"npm" -v'
Cannot find module 'C:\cwd\node_modules\npm\bin\npm-cli.js'
✅
'yarn -v'
(works as expected)
✅
'"C:\path\to\yarn" -v'
(works as expected)
OS: Win10
Node: v16., v17. (tried several of them)
EDIT: This seems to be a cmd-specific problem. If I set processOptions.shell = 'bash', it does not occur.
Full Error Message
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\cwd\yarn.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Done - code 1 signal null
Thoughts
It appears that there is a special logic that is triggered, iff the "executable" is in double quotes, and has no spaces or path separators in them...?
Not sure if feature or bug?
Code
// test.js
const cp = require('child_process');
const cmd = '"yarn" install';
const child = cp.exec(cmd);
// ###########################################################################
// process monitoring
// ###########################################################################
child.on('exit', (code, signal) => {
console.log('Done - code', code, ' signal', signal);
});
child.on('error', (err) => {
console.error(`Error:`, err);
});
// inherit stdio
child.stdout.pipe(process.stdout);
process.stdin.pipe(child.stdin);
child.stderr.pipe(process.stderr);
Turns out, it is a volta bug. I filed it here.
Easy to verify: Change the command to do other things on top of "yarn" install. The following still shows hi, but the yarn part still bugs out, so it is definitely not an issue with node or cmd:
const cmd = 'echo "hi" && "yarn" install';
const child = cp.exec(cmd);
Some more explanation: volta manages node, npm and yarn for you, making it very easy to install/uninstall/pin versions globally or even per folder/project. That means that "yarn" install does not actually run yarn, but actually this:
Runs a volta executable
Which will then run yarn...
...which evidently messed up the logic to look up the actual executable.
This happens only with yarn and npm. Everything else (thus far) seems fine, including node itself.

Extracting terraform resource changes with github-script#v5 action

I have a github workflow where I want to filter the terraform destroy changes from the terraform plan file and post that as comment in the PR.
- name: Terraform Plan
id: plan_json
run: |
terraform plan -out planfile 2>error.log
terraform show -json planfile > plan.json
continue-on-error: true
- uses: actions/github-script#v5
id: message
if: ${{ always() }}
with:
result-encoding: string
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('./plan.json'));
var message = '';
for (const changes in report.resource_changes) {
message += `${changes.change.actions[0]} ${changes.name} (${changes.type})\n`
};
console.log('Message: ', message);
return message;
When I run the workflow it gives this error:
SyntaxError: Unexpected token c in JSON at position 1
at JSON.parse (<anonymous>)
at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4942:56), <anonymous>:4:21)
at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4943:12)
Error: Unhandled error: SyntaxError: Unexpected token c in JSON at position 1
at main (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4997:26)
at Module.272 (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4981:1)
at __webpack_require__ (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:24:31)
at startup (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:43:19)
at /home/runner/work/_actions/actions/github-script/v5/dist/index.js:49:18
at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:52:10)
at Module._compile (internal/modules/cjs/loader.js:959:30)
I don't have any nodejs/javascript experience so I have no clue what I am doing wrong here.
The actual plan file can be found here.
When I run the nodejs script locally it works.
❯ node tfplan.js
Message: create, rg (azurerm_resource_group)
create, rg-name (random_pet)
- uses: hashicorp/setup-terraform#v1
with:
terraform_wrapper: false
terraform_wrapper: false had to be added to the terraform setup task.
For more info check this.

Cube.js Playground: Error while loading DB schema

I am currently learning Javascript/HTML/CSS in order to build some data dashboard.
I have found this tutorial https://d3-dashboard.cube.dev/setting-up-a-database-and-cube-js
Currently I am getting stuck at this part:
The next step is to create a Cube.js data schema.
When opening the Cube.js playground at: http://localhost:4000, I get the following output in my terminal:
🦅 Dev environment available at http://localhost:4000, I get the following error:
🚀 Cube.js server (0.21.1) is listening on 4000
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE>
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
And in the Cube.js playground webpage view:
Error while loading DB schema
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE> at
GetAddrInfoReqWrap.onlookup [as oncomplete](dns.js66:26)
I have edited the following file:
d3-dashboard/node_modules/#cubejs-backend/server-core/core/index.js
, with:
const checkEnvForPlaceholders = () => {
const placeholderSubstr = '<YOUR_DB_';
const credentials = [
'CUBEJS_API_SECRET=SECRET',
'CUBEJS_DB_TYPE=postgres',
'CUBEJS_DB_NAME=ecom',
'CUBEJS_WEB_SOCKETS=true'
/*'CUBEJS_DB_HOST',*/
/*'CUBEJS_DB_NAME',*/
/*'CUBEJS_DB_USER',*/
/*'CUBEJS_DB_PASS'*/
];
Any input on what I am doing wrong here?
I am totally new to apps and front-ends, so it might be something "stupid" that I am sking, but I really would like to learn from my mistakes :)
Thank you for your time and potential inputs/help!
Have a great day :)
You definitely should not edit any files in the node_modules directory. You should store the env variables in the .env file.
-your-cubejs-server-root
--schema
--.env
--//..
And it may look like
CUBEJS_DB_HOST=localhost
CUBEJS_DB_NAME=cubejs
CUBEJS_DB_USER=root
CUBEJS_DB_PASS=
CUBEJS_DB_TYPE=mysql
CUBEJS_API_SECRET=secret
The error you're getting is saying that the connection to the DB cannot be established. Because you're missing the proper CUBEJS_DB_HOST= variable.
The minimum required set of variables differs for each database and can be found here https://cube.dev/docs/connecting-to-the-database

Error while initializing app TypeError: parentVal.concat is not a function

I created a fresh Nuxt.js project: npx create-nuxt-app project
Then I launch the server: cd project && npm run dev
Till this point is all ok.
Now I want to install nuxt-i18n: npm i nuxt-i18n and then I added it in nuxt.config.js:
modules: [
['nuxt-i18n', {
// Options
}]
I am getting the following error in the console of the development tools (with a page showing blank):
app.js:455 [nuxt] Error while initializing app TypeError: parentVal.concat is not a function
at mergeHook (commons.app.js:11924)
at mergeField (commons.app.js:12185)
at mergeOptions (commons.app.js:12176)
at Vue._init (commons.app.js:15301)
at new Vue (commons.app.js:15419)
at _callee5$ (app.js:1317)
at tryCatch (commons.app.js:5854)
at Generator.invoke [as _invoke] (commons.app.js:6088)
at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/_nuxt/commons.app.js:5906:21)
at asyncGeneratorStep (commons.app.js:33)
What causes this and how to fix it?
It seems due to a sub dependency issue from vue-meta used by vue-i18n
(see the open issue https://github.com/nuxt-community/nuxt-i18n/issues/127)
as workaround, try to set the seo option at false :
// nuxt.config.js
['nuxt-i18n', {
seo: false
}]
It was due to vue-meta. Vue-meta 1.5.5 was released that is fixed this issue.
So you can update it and it will fine

Sails.js swig template not working

I installed Sails.js 0.9.4 and created an application that uses the swig template engine with the following command:
sails new sailsproject--template=swig
When I try to run the app via sails lift I get the following error:
C:\Users\akis\Desktop\sailsproject>sails lift
C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\ap
plication.js:174
if ('function' != typeof fn) throw new Error('callback function required');
^
Error: callback function required
at Function.app.engine (C:\Users\akis\AppData\Roaming\npm\node_modules\sails
\node_modules\express\lib\application.js:174:38)
at Array.loadExpress [as 1] (C:\Users\akis\AppData\Roaming\npm\node_modules\
sails\lib\express\index.js:70:7)
at listener (C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modul
es\async\lib\async.js:462:46)
at C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\async\l
ib\async.js:416:17
at Array.forEach (native)
at _each (C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\
async\lib\async.js:32:24)
at Object.taskComplete (C:\Users\akis\AppData\Roaming\npm\node_modules\sails
\node_modules\async\lib\async.js:415:13)
at processImmediate [as _immediateCallback] (timers.js:330:15)
C:\Users\akis\Desktop\sailsproject>
Does anyone know why? It works perfectly with jade or ejs and the docs in the /config/views.js file state that Sails supports other templates as well (including swig).
This is a bug that is fixed in the development branch of sails and should be fixed in the next release.
See: https://github.com/balderdashy/sails/issues/868

Categories