Source "#openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported - visual-studio-code

I've imported the Open Zeppelin ERC721 token standard into my VS Code with the Solidity extension, but see the following warnings on all my OZ import statements:
Screenshot of error
Why is this happening and what is the workaround for this warning?
What I've tried:
change default workspace compiler to localNodeModule (began to throw other warnings like on the pragma solidity line)
Example of solution I've tried

Just install the Solidity+Hardhat Extension ,this will take care of the errror.

run below command
npm install #openzeppelin/contracts
Change the import line like this
import "./node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";

You could try this solution here, the only one that helped me.
https://stackoverflow.com/a/72241149/7537543
When you compile programmatically using solc, new syntax was introduced, which you have to include in compile.js.
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
var output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
You should have a helper function for finding imports
function findImports(relativePath) {
//my imported sources are stored under the node_modules folder!
const absolutePath = path.resolve(__dirname, 'node_modules', relativePath);
const source = fs.readFileSync(absolutePath, 'utf8');
return { contents: source };
}

Unfortunately I ran into this error too & just gave the path manually:
import "/home/ev1lclow3n/node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";
This solved my error.
(I'm a linux user so path may differ for you)
Thanks ;-)

you have to manually guide the open zepplin import to its source file if you have it downloaded in your node modules then all you have to do is to change its path like this " ../node_modules/" and also make sure to use the latest extension of juan blanco's solidity extension and solidity and hardhat extension and if you are following a tutorial your first lines of codes would probably be import "hardhat/console.sol"; all you have to do here is to manually direct only this file to its designated place and the others would do it by themselves.

What you have to do is:
If you have "Solidity by Juan Blanco" for Truffle and "Solidity by Nomic Foundation" for Hardhdat, and if you are using Hardhat, disable the one by Juan Blanco and just use the one by Nomic Foundation, it just worked for me.
Screenshot
Make sure to create a Hardhat project (npx hardhat) and install:
npm install --save-dev "hardhat#^2.12.7" "#nomicfoundation/hardhat-toolbox#^2.0.0"
npm i #openzeppelin/contracts

Ok. That was a dumb question. Two things you have to do:
(1) Install the OZ library via
npm install #openzeppelin/contracts
(2) If you see Error HH606 (i.e. project can't compile), it's likely because The Solidity version pragma statement in these files doesn't match any of the configured compilers in your config.. Ensure that your pragma version matches the version in your hardhat config.
Hope this helps.

Related

VSCode says "Failed to run custom build command" on cbindgen, but it actually works

I have a Rust (2021) lib. It compiled fine.
I added a build.rs file with this in it:
extern crate cbindgen;
use std::env;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::Builder::new()
.with_crate(crate_dir)
.generate()
.expect("Unable to generate bindings")
.write_to_file("rush_engine.h");
}
Next, I added this to the bottom of Cargo.toml:
[build-dependencies]
cbindgen = "0.20.0"
Finally, I added a cbindgen.toml file with the contents of this:
https://github.com/eqrion/cbindgen/blob/master/template.toml
If I run 'cargo build' the .h file appears as expected and there's no errors from cargo in the terminal window.
However, VS Code has the entire Cargo.toml underlined under every word with red squiggles and there's an error message at the bottom saying 'failed to run custom build command for lib_name'.
I cannot find a solution to this (have removed everything and re-added, cleaned out target folder, etc) and though it's not breaking anything, it's kinda off-putting that this glaring error keeps showing.
Any pointers on how to solve this would be grately appreciated.
Cheers
Jase
Additional requested info:
The Cargo.toml at issue looks like this:
[package]
name = "rush_engine"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "staticlib"]
[dependencies]
chrono = "0.4"
[build-dependencies]
cbindgen = "0.20.0"
The VSCode extensions I'm using are:
rust-lang.rust (version 0.7.8)
...that's literally it. I don't see anything else rust related in running extensions.
Something Francis Gagné (thanks!) said got me wondering and experimenting. That's how I found a solution.
The solution (for me) was uninstall the official Rust extension, then install the rust-analyzer extension. This seems to have the exact same functionality, and it's not red-squiggling my entire Cargo.toml file, too!

Visual Code Studio, File Import Callback not Supported - File Source not Found

While trying to troubleshoot another issue with my project, I must've broken something along the way, but I have no idea how to fix this.
These are my import statements for the project:
pragma solidity >=0.6.6;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
And this is my brownie-config.yaml
depencencies:
- OpenZeppelin/openzeppelin-contracts#3.4.0
- smartcontractkit/chainlink-brownie-contracts#1.0.2
compiler:
solc:
remappings:
- '#openzeppelin=OpenZeppelin/openzeppelin-contracts#3.4.0'
- '#chainlink=smartcontractkit/chainlink-brownie-contracts#1.0.2'
But despite all this working until yesterday, trying to compile only gives me these errors:
PS C:\Users\XXX\Desktop\Project> brownie compile
INFO: Could not find files for the given pattern(s).
Brownie v1.16.4 - Python development framework for Ethereum
New compatible solc version available: 0.6.6
Compiling contracts...
Solc version: 0.6.6
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
contracts/AdvancedCollectible.sol:3:1: ParserError: Source "OpenZeppelin/openzeppelin-contracts#3.4.0/contracts/token/ERC721/ERC721.sol" not found: File not found.
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
^-------------------------------------------------------^
contracts/AdvancedCollectible.sol:4:1: ParserError: Source "smartcontractkit/chainlink-brownie-contracts#1.0.2/contracts/src/v0.6/VRFConsumerBase.sol" not found: File not found.
import "#chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
^---------------------------------------------------------^
How do I solve this?
I've seen some answers to similar issues referencing node.js or local copies of the stuff I'm trying to import, but isn't this command supposed to pull stuff off github?
Why is it failing to do so out of nowhere?
Install Openzeppelin at the root of your folder by using npm
npm i #openzeppelin/contracts
same thing for Chainlink
This is because the solidity extension is looking in the wrong directory.
Below step fixed the issue for me -
Change the settings in Solidity extension in VSCode.
The default settings include: "solidity.packageDefaultDependenciesContractsDirectory": "contracts" Users need to change the setting from contracts to an empty string. "solidity.packageDefaultDependenciesContractsDirectory": ""
Source - https://github.com/juanfranblanco/vscode-solidity/issues/178

Why can't I add a package (module) I created in Julia?

I am having trouble installing a module I created in Julia. I am running the Julia plugin under Visual Studio Code. If I run the file below with Ctrl+F5 I get a message
ERROR: LoadError: ArgumentError: Package Utils not found in current path:
- Run `import Pkg; Pkg.add("Utils")` to install the Utils package.
This is the file:
module demo
using Utils
greet() = print("Hello World!")
end # module
If I follow the advice on the error message I get another error message:
ERROR: LoadError: The following package names could not be resolved:
* Utils (not found in project, manifest or registry)
I also tried inserting this line:
import Pkg; Pkg.add(path="C:/Dropbox/Code/Julia/demo/src/Utils.jl")
and got this message (although the path definitely exists):
ERROR: LoadError: Path `C:/Dropbox/Code/Julia/demo/src/Utils.jl` does not exist.
The files demo.jl and Utils.jl are in C:\Dropbox\Code\Julia\demo\src\ and the demo project has been activated as can be seen in the REPL. The OS is Windows 10 Pro.
Any help will be greatly appreciated. Lots of time wasted trying to make this work.
Module and packages are not the same things. In short, packages are modules plus a set of metadata that make it easy for the package to be found and interact well with other packages. See here for a tutorial to write Julia packages:
https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages
In your case, if you want to load a local module, just type include("fileWhereThereIsTheModule.jl") followed by a using Main.MyModule or using .MyModule. Note the dot... without it, Julia would indeed look for a package and to let it find your Demo or Util module you would have to either change an environmental variable or place your module file in certain predefined folders. Using include followed by the "absolute or relative position" of the module you don't have to do either.

how to import mjs in vscode?

Is it possible to make a vscode extension made of mjs files?
because I tried to make an extension with mjs files only, in order to have full es6 features without TypeScript.
But it does not run:
If I make the extension with $ vsce package it does not give any error but it makes an extension that does not work when installed: the contributions that I've put in the package.json are present but vscode shows an error popup that says
Activating extension 'my.ext' failed: Must use import to load ES Module: c:\vsext\extension.mjs.
and every command I try to run gives an error
command 'my.cmd' not found
If I run the extension on the debugger, and the breakpoint on uncaught exception option flagged, it breaks on /src/vs/workbench/api/node/extHostExtensionService.ts:88.
After further search, I noticed that this exception is generatend when the script tries to load the first mjs module.
there is something I can do in order to include my mjs library files?
I think that this behaviour could also impact the use of npm modules with mjs files.
EDIT
Found (kind of) a way using esm:
The idea is to use esm to handle es6 imports and share the vscode object between imported modules
this could seem quite tricky but when I tried to just import * as vscode from "vscode" im my mjs files, vscode complained that can't find module vscode.
so I've done the following
add 'esm' as dependency
in all the files where vscode is used, remove the import of vscode and add something like this function
var vscode; // will store vscode obj
export function IMPORTVSCODE(vscodeInstance){
vscode = vscodeInstance
}
create a init file where you require vscode (with node native require) and your main module (with esm require)
in the init file call main.IMPORTVSCODE(vscode)
on all the files A that imports a file B that need vscode, before use the exported stuff from file B, call B.IMPORTVSCODE(vscode)
for example
// init.js
const vscode = require("vscode")
const esm = require("esm")(module/*, options*/)
const main = esm("./main.mjs")
main.IMPORTVSCODE(vscode)
module.exports = main
// main.mjs
import * as other from "./other.mjs"
var vscode; // will store vscode obj
export function IMPORTVSCODE(vscodeInstance){
vscode = vscodeInstance
}
function activate(){
other.IMPORTVSCODE(vscode)
other.methodThatNeedsVscode()
}
// other.mjs
var vscode; // will store vscode obj
export function IMPORTVSCODE(vscodeInstance){
vscode = vscodeInstance
}
export function methodThatNeedsVscode(){
vscode // ...use vscode
}
My extension runs fine now!
But I think that better ideas could be found, so if somebody has some finest solutions, please share them

Composer Package Error

I'm not sure what I've done wrong here.
I've created a package and I'm trying to require it by using this:
composer require "karl-ballard/gravatar" : "1.0.*"
However, I keep getting this as an output:
InvalidArgumentException
Could not find package 1.0.* at any version for your minimum-stability
(stable). Check the package spelling or your minimum-stability
Can anyone tell me what I'm doing wrong?
https://github.com/krballard/gravatar
The syntax is wrong, see Docs for Composer require.
You copied the line for composer.json directly to the command line.
It's composer require "karl-ballard/gravatar:^1.0"