Truffle's artifact is undefined when running truffle migrate - solidity

I'm trying to run truffle migrate on two js files: 1_initial_migration.js and 2_deploy_contracts.js. I can successfully compile my .sol files to .json ABIs but then when I try to migrate I get the following error:
const Migrations = artifacts.require("Migrations");
^
TypeError: Cannot read property 'require' of undefined
Here's how I've utilised artifacts in my js files:
const { artifacts } = require("truffle");
const Migrations = artifacts.require("Migrations");
truffle version results are as follows:
Truffle v5.1.39 (core: 5.1.39)
Solidity v0.5.16 (solc-js)
Node v14.16.0
Web3.js v1.2.1
Also I'm following this course on youtube.
I've seen a couple of posts about changing solitidy version, solc(?) version, and truffle version. I've tried downgrading my global truffle version to 5.1.39 and upgrading the solidity version at the start of my .sol files to ^0.6.0, as that seems to be the recommendations from those posts:
https://ethereum.stackexchange.com/questions/84388/solidity-0-6-0-truffle-compile-error-cannot-read-property-of-undefined
https://github.com/trufflesuite/truffle/issues/4191

Try these files:
1_initial_migration.js:
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
2_deploy_contracts.js:
const YourContractName = artifacts.require("YourContractName");
module.exports = function(deployer) {
deployer.deploy(YourContractName);
};

Don't do anything just update the truffle
Your error will be removed🥇

Related

Cannot configure Jest for WebStorm/IntelliJ

I have installed Jest using npm :
npm i jest --save-dev
At the package level I also have a Jest config file: jest.config.js which is very simple and just contains :
const config = {
verbose: true,
};
module.exports = config;
However if I look at a test that I wrote, the expect() cannot be compiled :
On closer inspection WebStorm/IntelliJ thinks that describe() and it() belong to mocha, and not jest.
How do I point IntelliJ/WebStorm to jest and not to mocha? I can't seem to find anything in the settings.

`Module not found: 'vue-server-renderer'`

I am trying to compile my vue component to unit test it.
I added the import { render } from "#vue/server-test-utils"; line at the beginning of my test file. I also run the command npm i --save-dev #vue/server-test-utils which completed successfully. I checked the node_modules folder that the dependency was indeed installed.
But still when I run the test file I am getting the error:
WEBPACK Failed to compile with 1 error(s)
Error in ./node_modules/#vue/server-test-utils/dist/vue-server-test-utils.js
Module not found: 'vue-server-renderer'
Here I found a similar issue. I tried adding the
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.isServerBuild = false;
return options;
});
}
to my webpack config, but it did not help.
I am using Vue 2. Maybe someone happened to stumble across this issue and knows a solution?
npm install --save-dev vue-server-renderer #vue/server-test-utils worked.
It seems that we have to install the two packages: the vue-server-renderer and then the #vue/server-test-utils.

Can I get a webpack resolve alias working on android with expo?

I'm trying to get a preact library to work with expo/react-native
It works find on web using this alias in webpack:
// webpack.config.js
const createExpoWebpackConfigAsync = require('#expo/webpack-config');
module.exports = async function(env, argv) {
const config = await createExpoWebpackConfigAsync(env, argv);
config.resolve.alias = {
...config.resolve.alias,
'preact': 'react'
}
return config;
};
But on android I get an error: Unable to resolve "preact" from "node_modules/.../....
Does anyone know how to get the same kind of alias working outside of web?
I was unable to find a solution where webpack's alias was usable outside of Web on Android. I needed it on account of the typical invalid Hook call caused by duplicate React modules being used.
Supposedly Yarn workspaces might fix this as well but I couldn't get that working.
The solution I found and was mildly painless was to update my local libraries' devDependencies so they all use the same React module being used in the main project's dependencies.
- app
|
|-- package.json dependency: "react":"18.1.0"
- local_library
|
|-- package.json devDependency:
"react": "file:../../../node_modules/react",

Why does the solidity compiler throw a parse error on import statements? What's the workaround?

I used npm install to install my node package dependencies. My node package dependencies look like the following:
"dependencies": {
"blockcypher": "^0.2.0",
"fs-extra": "^7.0.1",
"ganache-cli": "^6.2.4",
"mocha": "^5.2.0",
"openzeppelin-solidity": "^2.0.0",
"solc": "^0.4.24"
}
When I run the following compile script using node I get the following error within EVERY contract that has an import statement that references dependency in my node_modules.
I'm using Solidity Version: ^0.4.24
Solidity Error: ParseError: Source
"node_modules/openzeppelin-solidity/ect.." not found
const path = require("path"); //Delete all the contents in the build folder
const solc = require("solc"); //solidity compiler
const fs = require("fs-extra"); // Gives us access to the file system
//Require The Import Statements From The Contract
// import "node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
// import "node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol";
// import "node_modules/openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
//var data = require("node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.json");
//How do I use this?
const buildPath = path.resolve(__dirname, "build");
fs.removeSync(buildPath);
const campainPath = path.resolve(__dirname, "Contract.sol");
// const campainPath = path.resolve(__dirname, "contracts", "Esgro.sol");
const source = fs.readFileSync(campainPath, "utf8");
console.log("\n\n\t Compilation Output \n\n\n");
console.log(solc.compile(source, 1));
const output = solc.compile(source, 1).contracts; //Internal Error
console.log("\n\n\t Compilation Output \n\n\n");
console.log(output);
fs.ensureDirSync(buildPath);
for (let contract in output) {
// fs.outputJsonSync(
// path.resolve(buildPath, contract.replace(":"", "") + ".json"),
// output[contract]
// );
console.log("\n\n\t output[contract] \n\n\n");
console.log(output[contract]);
fs.outputJsonSync(path.resolve(buildPath, contract), output[contract]);
}
//Compile both contracts with the solc compiler
//Write the output to the build directory
How do you get the compiler to "connect" with the third party dependencies on a local machine? Any help or pointers would be greatly appreciated.
the correct syntax for importing an npm dependency into a .sol file is the follows:
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol"; //You don't need to write node_modules
openzeppelin's documentation says:
You need an ethereum development framework for the above import
statements to work!
so, probably is better that you use Truffle or Embark to compile and migrate your contract.
One last thing, OpenZeppelin uses the version ^ 0.5.0 of solidity,
so when you go to compile remember to use a suitable version of solc.
Let me know if it worked

Yeoman custom generator not loading dependencies from package.json

I've created a Yeoman custom generator. Within the index.js file I want to perform some text replacement on some files. In package.json I have added the dependency replace then when I require('replace') in index.js and run the generator, I get the error Cannot find module 'replace'. I have tried different modules from NPM and running the generator fails for all of them - it fails to find the module.
The appropriate part of package.json
"dependencies": {
"replace": "~0.2.9",
"yeoman-generator": "~0.16.0",
"chalk": "~0.4.0"
},
Start of index.js
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var replace = require('replace');
var MyGenerator = yeoman.generators.Base.extend({
init: function () {
this.pkg = require('../package.json');
The generator fails when it hits the Replace require. Chalk and Yeoman Generator don't fail and they're loaded in the same way.
Why don't my added modules load?
Did you run npm install after manually adding that line to package.json? The preferred way to install a package is by running: npm install --save _package_. It will download the latest release, and save it to your package.json.