I just started learning webpack to manage dependencies in my project. I am trying to use it to build bundles for my typescript and javascript files. For the typescript files, I am using the ts-loader
plugin for handling it. For CSS, I am using the mini-css-extract
and an optimize-css-assets
plugin. When I try to run webpack, I get the following error and I am not able to figure out what might be causing this error.
user@system spl % npm run build
> spl@1.0.0 build /Users/user/Downloads/spl
> webpack --config webpack.config.js
/Users/user/Downloads/spl/node_modules/neo-async/async.js:16
throw new Error('Callback was already called.');
^
Error: Callback was already called.
at throwError (/Users/user/Downloads/spl/node_modules/neo-async/async.js:16:11)
at /Users/user/Downloads/spl/node_modules/neo-async/async.js:2818:7
at processTicksAndRejections (internal/process/task_queues.js:79:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! spl@1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the spl@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_logs/2020-05-14T14_23_32_985Z-debug.log
The following is my webpack.config file that I am using to build my dist files.
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = {
mode: 'production',
entry: "./static/js/index.js",
output: {
filename: "bundle.[contentHash].js", // File name with hash, based on content
path: path.resolve(__dirname, 'dist')
},
optimization: {
minimizer: [
new OptimizeCssAssetsPlugin(),
new TerserPlugin(),
new HtmlWebpackPlugin({
template: "./static/index.html",
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
removeComments: true
}
})
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].[contentHash].css"
}),
new CleanWebpackPlugin(),
],
module: {
rules: [
{
test: /.html$/,
use: [ "html-loader" ]
},
{
test: /.[tj]s$/,
use: "ts-loader",
exclude: /(node_modules|tests)/
},
{
test: /.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
}
],
},
resolve: {
alias: {
src: path.resolve(__dirname, 'src'),
static: path.resolve(__dirname, 'static'),
},
extensions: [ '.ts', '.js' ]
}
}
Содержание
- «callback already called» error #3008
- Comments
- Issue
- Steps to Reproduce
- Expected Behavior
- Actual Results
- Environment
- Uncaught Error: Callback was already called. #92
- Comments
- Stack Trace
- Commands
- Config
- Installed Packages
- Autoreload failed. Got Error: Callback was already called #84
- Comments
«callback already called» error #3008
- I’ve asked for help in the Truffle Gitter before filing this issue.
Issue
Deploying on testnet fails with Error: callback already called (but deployment on Ganache succeeds).
The mentioned callback is at /node_modules/truffle/build/webpack:/
Steps to Reproduce
Create the .env as required here https://github.com/okwme/truffle-shavings
Delete truffle-config,js
You should get the error
Expected Behavior
Contract should be deployed on Rinkby or any other testnet
Actual Results
/async/lib/async.js:358 callback(err); ^ Error: Callback was already called. at /Users/Pm/Documents/Ethereum/test2/node_modules/truffle/build/webpack:/
/async/lib/async.js:358:1) at WriteStream.emit (events.js:315:20) at WriteStream.destroy (/Users/Pm/Documents/Ethereum/test2/node_modules/truffle/build/webpack:/
/level-ws/level-ws.js:140:1) at finish (_stream_writable.js:681:14) at processTicksAndRejections (internal/process/task_queues.js:84:21) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.»>
Environment
- OSX 10.15.3 (Catalina)
- Web3.js v1.2.1
- Truffle v5.1.23 (core: 5.1.23)
• Solidity v0.5.16 (solc-js) - Node v14.0.0
- npm 6.14.4
• yarn 1.22.4
The text was updated successfully, but these errors were encountered:
To anyone meeting this problem it could be due to
(1) Node 14. Revert to LTS (12.16.2 at time of writing)
(2) Anything else. Sorry. I formatted my computer in the meantime. Maybe some elder sudo messing up with my config.
@TheDApact thanks for reporting this and for the repro steps! I’ll take a look into why this is happening.
I was unable to duplicate your error. I tried with both Node 10 and 12. I could successfully migrate to ropsten like you instructed. I wonder what could be going on here.
I was on Node 14.0 best bet it’s from Node.
Node 12.0 does it!
I was able to on Node 14 too. Try upgrading your version of Truffle in the package.json . Currently it is set at ^5.0.2 . Set it to at least ^5.1.0 . My guess is that you are experiencing a bug we have already fixed. I was using the latest version of Truffle installed globally on my machine. Let me know what happens.
Still getting the same error with node 14.0 after upgrading truffle to ^5.1.0 in package.json .
At least we confirmed it stems from node 14.0
edit: same with 5.1.23
No I meant to say that I was able to successfully migrate to ropsten using Node 14. I’m not sure what’s up with this. Are you using a globally installed version of Truffle? If so, can you do a truffle version just to ensure you are using the most recent version? I know we had some bug a while back that gave the error message that you reported.
Here is my environment
npx truffle migrate will work if I downgrade Node to 12.16.2
Here are the packages installed globally on my (just formatted) OSX Catalina
Worse mentioning that I added the snippet below to package.json found in the box, to fix an error with fsevent (see nodejs/node#27389)
Hmm weird, it looks like I can duplicate your error with Node 14 today. I think it is unrelated to the resolutions property you mentioned above as I could duplicate it without it. We’ll have to look into this later, thanks for the report! I really would like to get rid of the async library from the Truffle codebase 🙂
I really would like to get rid of the async library from the Truffle codebase 🙂
Your wish is my command 🧞
So the async library was removed from the latest version of Truffle (5.1.25) and re-attempting this migration I get the same error. So it looks like this error does not come from Truffle’s direct usage of the library but is rather something else. More investigation will be necessary.
Same error with this:
But everything is just fine with this:
I am having the same error. Is this a bug?
/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:358
callback(err);
^
Error: Callback was already called.
Truffle v5.1.28 (core: 5.1.28)
Solidity — 0.6.8 (solc-js)
Node v14.3.0
Web3.js v1.2.1
I was experiencing the same problem with Node v14.4.0
After switching to Node v12.0.0 with nvm it worked like a charm.
@PierreMarieRiviere This is an issue related to ganache-core ‘s internals not yet being Node 14 compatible (trufflesuite/ganache#732).
You should be able to to deploy to any of the production networks (including testnets) with truffle on Node 14, by skipping the dry run ( truffle migrate —network rinkeby —skipDryRun ). The dry run uses ganache’s forking feature to simulate the deployment for production networks.
I was experiencing the same problem with the following setting:
Truffle v5.1.31
node v14.4.0
Solidity v0.5.0
It works for me after I tried ‘truffle migrate —network rinkeby —skipDryRun’
@PierreMarieRiviere This is an issue related to ganache-core ‘s internals not yet being Node 14 compatible (trufflesuite/ganache-cli#732).
You should be able to to deploy to any of the production networks (including testnets) with truffle on Node 14, by skipping the dry run ( truffle migrate —network rinkeby —skipDryRun ). The dry run uses ganache’s forking feature to simulate the deployment for production networks.
Источник
Uncaught Error: Callback was already called. #92
- Upload a relatively large folder containing images of various sizes
Atom Version: 0.179.0
System: linux 3.16.7-7-desktop
Thrown From: remote-sync package, v2.4.0
Stack Trace
Uncaught Error: Callback was already called.
Commands
Config
Installed Packages
The text was updated successfully, but these errors were encountered:
Same issue here.
According to the source code and error, there should be a error msg in console or status panel? Someone who can put the error log?
This happened to me, too, — also using remote-sync. The issue was caused by the server that I was trying to save to not having any more room on the hard drive. Anyways — one thing to look out for if this error shows up.
+1 on latest update 4.0.0
Happens along with:
@yongkangchen Any update on this?
same issue here
@yongkangchen This is a critical issue that renders remote-sync completely unusable in certain conditions, could you please take a look at your source code and find out why the async callback may be called more than once?
Same issue. Maybe help this caolan/async#1279
I had this error when I simply had an invalid ftp username.
In my case this issue appears while pageant was not running (agent auth.). After starting pageant it’s working.
This happens to me as well. It is not async‘s fault, but async should provide way better error messages.
See » the offending line». Here I’m trying to access limits on data . Problem is that limits doesn’t exist. This throws an exception which async catches. Then async emits that ill-formed and misleading error message.
@hfossli I don’t think that the problem is with async or that its providing the wrong error, the problem is that you are actually calling the callback twice. You should be using a finally construct essentially:
Источник
Autoreload failed. Got Error: Callback was already called #84
Every time Autoreload happens, Sails auto-migration will run but I got following error:
The text was updated successfully, but these errors were encountered:
What is «Sails auto-migration» ? Is it a package ?
Be aware that sails-hook-autoreload is incompatible with a lot of packages.
This should work without trouble. Please, provide a reproduction repo with minimal setup.
same issue here. I have a fresh new project, this is my package.json:
Steps to reproduce:
Issue dissappears if you drop api/models/Model.js file.
Thanks @gleam-ru I’m going to have a look. As I don’t use sails 1.x for now I didn’t dive into this earlier. If you succeed making a FIX, don’t hesitate to PR or share it here.
Hello, I have updated my dependencies and now I have the same issue. After some search, I found that the «async» module have breaking changes in its v2.0.0, and it seems to match this issue :
«Calling a callback more than once is considered an error, and an error will be thrown. This had an explicit breaking change in waterfall. If you were relying on this behavior, you should more accurately represent your control flow as an event emitter or stream.»
Same thing here, with a fresh Sails 1.0 generated project
I uninstall sails-hook-autoreload until a fix is available 🙂
No update on this blocking issue since months, it seems this project is dead like Sails.js, sad.
In ‘./config/models.js’ file I add »
@Wisperus thanks, nice workaround while waiting for a fix
Any update on a fix? Would be great to not disable archiveModel 🤔
in model config
The archiveModelIdentity: false worked for me too! It would be great if this can be resolved anyway.
Did someone found a fix for this one ? The problem looks to be located in waterline so we need another way to reload ORM otherwise the callback is called more than once.
also worked for me using the actual sails 1.0 version.
Anyway, for those stumbling upon the same question o similar scenario of mine:
I wanted to use the sails command (eg., sails console —drop ) along with the automatic reload, so I could test changes in waterline models right away after ctrl+save them.
Источник
Thanks for reply, I am gonna check that out.
Note: I am still using the library, what was problematical (I am importing only one except the async), but I have rewritten it this way, and it works — but I really cant see, where was the problem. Maybe you could see(?), maybe it would be helpful for someone other.
So, this WORKS:
const listJobs = (next) => {
next(null, {
queued: {},
running: {},
done:{},
});
return null;
};
const getSystemInfo = (next: Function) => {
usage.lookup(process.pid, (err, result) => {
if (err) {
return next(err);
}
const ret = result;
ret.memoryFormatted = `${Math.round(ret.memory / 1024 / 1024)}M`;
return next(null, ret);
});
};
export const status = (req: Object, res: Object) => {
async.parallel({
systemInfo: getSystemInfo,
jobsList: listJobs,
}, (err, result) => {
if (err) {
return res.send({ err });
}
const ret = result;
async.eachOf(ret.jobsList.running, (data, url, next) => {
ret.jobsList.running[url].tail = `${req.protocol}://${req.get('host')}/tail/${encodeURIComponent(url)}`;
return next();
}, (err) => {
if (err) {
return res.send({ err });
}
return res.send(ret);
});
return null;
});
};
The reason for the error «Callback was already called» is that the socket which is connected calls the callback twice. Once when it is connected and one when it times out due to non activity on its open connection. To illustrate I modified your program a little by adding a few log messages. If you look at the log messages(commented below) you will notice that the socket for port 80 calls the callback twice. Once when it connects and once when it times out. Hope this helps!
-J
"use strict";
const net = require('net');
const async = require('async');
function findPortStatus (host, port, timeout, cb) {
const socket = new net.Socket();
socket.setTimeout(timeout, () => {
// couldn't establish a connection because of timeout
console.log('Timeout for port: %s', port);
socket.destroy();
return cb(null, null)
});
socket.connect(port, host, () => {
// connection established
console.log('Connected to port: %s', port);
return cb(null, port)
});
socket.on('error', (err) => {
console.log('Error connecting to port: %s with message: %s', port, err.message);
// couldn't establish a connection
return cb(null, null)
})
}
const funcs = [];
for (let port = 0; port <= 80; port++) {
funcs.push(function (callback) {
findPortStatus('192.30.253.112', port, 4000, (err, port) => {
if (!err) {
return callback(null, port)
}
})
})
}
async.parallel(funcs, (err, ports) => {
if (err) {
console.error(err.message);
} else {
console.log('All ports checked');
for (let port of ports) {
if (port) {
console.log('Port open: ', port);
}
}
}
});
/*
vipers-mac-book-pro-2:jwadhwani$ node test.js
Error connecting to port: 0 with message: connect EADDRNOTAVAIL 192.30.253.112 - Local (0.0.0.0:51951)
Connected to port: 22
Connected to port: 80 //First callback called here
Timeout for port: 1
Timeout for port: 2
...
...
...
Timeout for port: 79
All ports checked
Port open: 22
Port open: 80
Timeout for port: 80 //callback called here the second time
/Users/jwadhwani/projects/node_modules/async/dist/async.js:844
if (fn === null) throw new Error("Callback was already called.");
^
Error: Callback was already called.
at /Users/jwadhwani/projects/node_modules/async/dist/async.js:844:36
at /Users/jwadhwani/projects/node_modules/async/dist/async.js:3676:17
at /Users/jwadhwani/projects/node_modules/async/dist/async.js:339:31
at findPortStatus (/Users/jwadhwani/projects/test.js:36:36)
at Socket.socket.setTimeout (/Users/jwadhwani/projects/test.js:14:28)
at Socket.g (events.js:286:16)
at emitNone (events.js:86:13)
at Socket.emit (events.js:185:7)
at Socket._onTimeout (net.js:333:8)
at tryOnTimeout (timers.js:228:11)
vipers-mac-book-pro-2:jwadhwani$
*/
Error — node_modules : Callback was already called
I am building SSR rendered Gatsby react application and I get the following error while doing «gatsby build». Been searching for a solution for this error for a good couple of days as it is hard to find out what is causing this error from the description itself. All the description says is «Callback was already called»
7 Answers 7
After days of searching for a solution for this nerve-wracking. Updating all my packages, this way below, removed the error.
I had similar error building Vuejs webpack project, But then I tried running build command using «nodejs command prompt» which was successful without error,
So I realized I should «update/upgrade Powershell» itself, which removed this darkness forever 😊
I am using vuejs (which uses webpack) and was running into this same issue. I was using yarn as my package manager and tried upgrading and reinstalling all my dependencies and clearing cache, nothing seemed to work.
Although I did find a solution for my case. It seems vuejs (or webpack — not entirely sure) is very case sensitive to the file and folder names, I had various case styles in my absolute folder path which seemed to cause a problem in git bash. When I used cmd however, it did work. I have reason to believe that cmd normalizes this issue.
In brief: Try cmd if git bash gave you errors.
Источник
Uncaught Error: Callback was already called. #92
Comments
wyqydsyq commented Feb 17, 2015
- Upload a relatively large folder containing images of various sizes
Atom Version: 0.179.0
System: linux 3.16.7-7-desktop
Thrown From: remote-sync package, v2.4.0
Stack Trace
Uncaught Error: Callback was already called.
Commands
Config
Installed Packages
The text was updated successfully, but these errors were encountered:
lordgiotto commented Sep 3, 2015
Same issue here.
vildhjarta8 commented Oct 20, 2015
yongkangchen commented Nov 5, 2015
According to the source code and error, there should be a error msg in console or status panel? Someone who can put the error log?
chapma26 commented Jan 7, 2016
This happened to me, too, — also using remote-sync. The issue was caused by the server that I was trying to save to not having any more room on the hard drive. Anyways — one thing to look out for if this error shows up.
ChristianGrech commented Apr 12, 2016
+1 on latest update 4.0.0
sompylasar commented May 12, 2016
Happens along with:
sompylasar commented Aug 23, 2016
@yongkangchen Any update on this?
abudayah commented Aug 24, 2016
same issue here
sompylasar commented Sep 5, 2016
@yongkangchen This is a critical issue that renders remote-sync completely unusable in certain conditions, could you please take a look at your source code and find out why the async callback may be called more than once?
okanatabag commented Nov 10, 2016
Same issue. Maybe help this caolan/async#1279
beenfishinglately commented Dec 15, 2016
I had this error when I simply had an invalid ftp username.
thomasfrobieter commented Aug 3, 2017
In my case this issue appears while pageant was not running (agent auth.). After starting pageant it’s working.
hfossli commented Sep 19, 2017
This happens to me as well. It is not async‘s fault, but async should provide way better error messages.
See » the offending line». Here I’m trying to access limits on data . Problem is that limits doesn’t exist. This throws an exception which async catches. Then async emits that ill-formed and misleading error message.
justinmchase commented Feb 13, 2018
@hfossli I don’t think that the problem is with async or that its providing the wrong error, the problem is that you are actually calling the callback twice. You should be using a finally construct essentially:
Источник
«callback already called» error #3008
Comments
PierreMarieRiviere commented Apr 26, 2020 •
- I’ve asked for help in the Truffle Gitter before filing this issue.
Issue
Deploying on testnet fails with Error: callback already called (but deployment on Ganache succeeds).
The mentioned callback is at /node_modules/truffle/build/webpack:/
Steps to Reproduce
Create the .env as required here https://github.com/okwme/truffle-shavings
Delete truffle-config,js
You should get the error
Expected Behavior
Contract should be deployed on Rinkby or any other testnet
Actual Results
/async/lib/async.js:358 callback(err); ^ Error: Callback was already called. at /Users/Pm/Documents/Ethereum/test2/node_modules/truffle/build/webpack:/
/async/lib/async.js:358:1) at WriteStream.emit (events.js:315:20) at WriteStream.destroy (/Users/Pm/Documents/Ethereum/test2/node_modules/truffle/build/webpack:/
/level-ws/level-ws.js:140:1) at finish (_stream_writable.js:681:14) at processTicksAndRejections (internal/process/task_queues.js:84:21) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.»>
Environment
- OSX 10.15.3 (Catalina)
- Web3.js v1.2.1
- Truffle v5.1.23 (core: 5.1.23)
• Solidity v0.5.16 (solc-js) - Node v14.0.0
- npm 6.14.4
• yarn 1.22.4
The text was updated successfully, but these errors were encountered:
PierreMarieRiviere commented Apr 27, 2020
To anyone meeting this problem it could be due to
(1) Node 14. Revert to LTS (12.16.2 at time of writing)
(2) Anything else. Sorry. I formatted my computer in the meantime. Maybe some elder sudo messing up with my config.
eggplantzzz commented Apr 27, 2020
@TheDApact thanks for reporting this and for the repro steps! I’ll take a look into why this is happening.
eggplantzzz commented Apr 27, 2020 •
I was unable to duplicate your error. I tried with both Node 10 and 12. I could successfully migrate to ropsten like you instructed. I wonder what could be going on here.
PierreMarieRiviere commented Apr 27, 2020 •
I was on Node 14.0 best bet it’s from Node.
Node 12.0 does it!
eggplantzzz commented Apr 27, 2020
I was able to on Node 14 too. Try upgrading your version of Truffle in the package.json . Currently it is set at ^5.0.2 . Set it to at least ^5.1.0 . My guess is that you are experiencing a bug we have already fixed. I was using the latest version of Truffle installed globally on my machine. Let me know what happens.
PierreMarieRiviere commented Apr 27, 2020 •
Still getting the same error with node 14.0 after upgrading truffle to ^5.1.0 in package.json .
At least we confirmed it stems from node 14.0
edit: same with 5.1.23
eggplantzzz commented Apr 27, 2020 •
No I meant to say that I was able to successfully migrate to ropsten using Node 14. I’m not sure what’s up with this. Are you using a globally installed version of Truffle? If so, can you do a truffle version just to ensure you are using the most recent version? I know we had some bug a while back that gave the error message that you reported.
PierreMarieRiviere commented Apr 28, 2020
Here is my environment
npx truffle migrate will work if I downgrade Node to 12.16.2
Here are the packages installed globally on my (just formatted) OSX Catalina
Worse mentioning that I added the snippet below to package.json found in the box, to fix an error with fsevent (see nodejs/node#27389)
eggplantzzz commented Apr 28, 2020 •
Hmm weird, it looks like I can duplicate your error with Node 14 today. I think it is unrelated to the resolutions property you mentioned above as I could duplicate it without it. We’ll have to look into this later, thanks for the report! I really would like to get rid of the async library from the Truffle codebase 🙂
nicholasjpaterno commented May 1, 2020
I really would like to get rid of the async library from the Truffle codebase 🙂
Your wish is my command 🧞
eggplantzzz commented May 11, 2020
So the async library was removed from the latest version of Truffle (5.1.25) and re-attempting this migration I get the same error. So it looks like this error does not come from Truffle’s direct usage of the library but is rather something else. More investigation will be necessary.
glowkeeper commented Jun 3, 2020 •
Same error with this:
But everything is just fine with this:
WillMandrill commented Jun 7, 2020
I am having the same error. Is this a bug?
/versions/node/v14.3.0/lib/node_modules/truffle/build/webpack:/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:358
callback(err);
^
Error: Callback was already called.
Truffle v5.1.28 (core: 5.1.28)
Solidity — 0.6.8 (solc-js)
Node v14.3.0
Web3.js v1.2.1
JavierTrujilloG commented Jun 24, 2020
I was experiencing the same problem with Node v14.4.0
After switching to Node v12.0.0 with nvm it worked like a charm.
CruzMolina commented Jun 24, 2020 •
@PierreMarieRiviere This is an issue related to ganache-core ‘s internals not yet being Node 14 compatible (trufflesuite/ganache#732).
You should be able to to deploy to any of the production networks (including testnets) with truffle on Node 14, by skipping the dry run ( truffle migrate —network rinkeby —skipDryRun ). The dry run uses ganache’s forking feature to simulate the deployment for production networks.
DanielTongAwesome commented Jun 27, 2020 •
I was experiencing the same problem with the following setting:
Truffle v5.1.31
node v14.4.0
Solidity v0.5.0
It works for me after I tried ‘truffle migrate —network rinkeby —skipDryRun’
@PierreMarieRiviere This is an issue related to ganache-core ‘s internals not yet being Node 14 compatible (trufflesuite/ganache-cli#732).
You should be able to to deploy to any of the production networks (including testnets) with truffle on Node 14, by skipping the dry run ( truffle migrate —network rinkeby —skipDryRun ). The dry run uses ganache’s forking feature to simulate the deployment for production networks.
Источник
OpenZeppelin has some neat docs to show how to create, deploy and interact with smart contracts centered around installing node, using the OpenZeppelin libraries, compiling via CLI, and deploying via Ganache which is a local blockchain environment for development and testing.
Some of you may remember TestRPC. Ganache is the new name of TestRPC.
The TestRPC quickly became more powerful than simply a blockchain environment used for testing. To stay with the sweet Truffle brand, we decided to rename it Ganache, as Ganache is (often) the core of your favorite chocolate truffle. It’s a much catchier name (and a much tastier one too).
https://www.trufflesuite.com/blog/testrpc-is-now-ganache
The problem though is when you follow the docs at https://docs.openzeppelin.com/learn/deploying-and-interacting and run:
npx ganache-cli --deterministic
to get a list of all the available accounts, you might encounter this error:
Ganache CLI v6.9.1 (ganache-core: 2.10.2)
Error: Callback was already called.
The problem is because you probably have node v14 installed. Run:
node -v
to check. For me, I installed node initially with the brew command
brew install node
which downloaded the latest version which was v14.5.0
The reason is an issue related to ganache-core’s internals not yet being Node v14 compatible. https://github.com/trufflesuite/ganache-cli/issues/732
Workaround
Install Node v12 for the time being. First run
brew search node
What this does is lists all available formula (aka packages) and the online equivalent is http://searchbrew.com/. You should see node, node@12, node@10 in the results.
Install node v12
brew install node@12
You should then get a green tick beside node and node@12. If you run node -v again you will still get the new version because you have to run 2 more commands.
brew unlink node
brew link node@12
You might get some errors here asking you to use the –overwrite flag to overwrite all the conflicting files (/usr/local/bin/npm already existing for instance) and also to add the –force flag because node@12 is keg-only.
Keg only means that node will only be installed at /usr/local/Cellar but not linked into places like /usr/local/bin, /usr/local/lib, etc. That means other software that depends on it has to be compiled with specific instructions to use the files in /usr/local/Cellar.
brew link --overwrite node@12 --force
Then check the version again with node -v and it should be at 12.x. Now if you run
npx ganache-cli --deterministic
You should get
Ganache CLI v6.9.1 (ganache-core: 2.10.2)Available Accounts
==================
(0) 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 (100 ETH)
(1) 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0 (100 ETH)
(2) 0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b (100 ETH)
(3) 0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d (100 ETH)
(4) 0xd03ea8624C8C5987235048901fB614fDcA89b117 (100 ETH)
(5) 0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC (100 ETH)
(6) 0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9 (100 ETH)
(7) 0x28a8746e75304c0780E011BEd21C72cD78cd535E (100 ETH)
(8) 0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E (100 ETH)
(9) 0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e (100 ETH)Private Keys
==================
(0) 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
(1) 0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1
(2) 0x6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c
(3) 0x646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913
(4) 0xadd53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743
(5) 0x395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd
(6) 0xe485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52
(7) 0xa453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3
(8) 0x829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4
(9) 0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773HD Wallet
==================
Mnemonic: myth like bonus scare over problem client lizard pioneer submit female collect
Base HD Path: m/44'/60'/0'/0/{account_index}Gas Price
==================
20000000000Gas Limit
==================
6721975Call Gas Limit
==================
9007199254740991Listening on 127.0.0.1:8545
Following an aging tutorial, I’m trying to learn how to test a smart contract:
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { abi, bytecode} = require('../compile')
let accounts;
let simpleStorage;
beforeEach(async ()=>{
// Get a list of all accounts
accounts = await web3.eth.getAccounts();
//Use one of those account to deply the contract
simpleStorage = await new web3.eth.Contract(abi)
.deploy({
data: bytecode,
arguments: ['Hi there!']
})
.send({
from: accounts[0],
gas: '1000000'
});
});
describe('SimpleStorage', ()=> {
it('deploy a contract', ()=>{
console.log(simpleStorage);
});
});
The compile.js
is like:
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inboxpath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(inboxpath, 'UTF-8');
var input = {
language: 'Solidity',
sources: {
'Inbox.sol' : {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
exports.abi = output.contracts['Inbox.sol']['SimpleStorage'].abi;
exports.bytecode = output.contracts['Inbox.sol']['SimpleStorage'].evm.bytecode.object;
And the contract Inbox.sol
:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract SimpleStorage {
uint256 public num;
function set(uint256 _num) public {
num = _num;
}
function get() public view returns (uint256) {
return num;
}
}
But I get this error:
0 passing (290ms)
1 failing
1) "before each" hook for "deploy a contract":
Uncaught Error: Callback was already called.
at /home/pc/Desktop/inbox/node_modules/ganache-cli/build/webpack:/ganache/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:43:1
at d.<anonymous> (node_modules/ganache-cli/build/webpack:/ganache/node_modules/ganache-core/node_modules/merkle-patricia-tree/node_modules/async/lib/async.js:358:1)
at d.emit (node:events:390:28)
at d.destroy (node_modules/ganache-cli/build/webpack:/ganache/node_modules/ganache-core/node_modules/level-ws/level-ws.js:140:1)
at finish (node:internal/streams/writable:763:14)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
/home/pc/Desktop/inbox/node_modules/mocha/lib/runner.js:965
throw err;
^
Error: done() called multiple times in hook <"before each" hook for "deploy a contract"> (of root suite)
at createMultipleDoneError (/home/pc/Desktop/inbox/node_modules/mocha/lib/errors.js:428:13)
at multiple (/home/pc/Desktop/inbox/node_modules/mocha/lib/runnable.js:290:24)
at done (/home/pc/Desktop/inbox/node_modules/mocha/lib/runnable.js:301:14)
at /home/pc/Desktop/inbox/node_modules/mocha/lib/runnable.js:371:11
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_MOCHA_MULTIPLE_DONE',
valueType: 'undefined',
value: undefined
}
version in package.json
:
"ganache-cli": "^6.1.8",
"mocha": "^9.1.3",
"solc": "^0.8.11",
"web3": "^1.6.1"
This error bugs me for hours now. Appreciate your help to resolve it.