Closed abcoathup closed 3 years ago
@abcoathup So i guess the ask is to detect the import and validate the settings?
@abcoathup, @caleteet was suggesting something similar to detect the solidity version, I guess that will fit rather well in the prompt process.. (prompt for solidity compiler version, if not the same and prompt to set zeppelin settings if not set)
Working on it, should have something very soon. The virtual events are attempting to slow me down. :)
Looking forward to this!
Hi guys,
So I was using @abcoathup example in this thread. I grabbed that contract put it into a test.sol
file in project root, installed openZeppelin and I do have:
"solidity.packageDefaultDependenciesContractsDirectory": ""
"solidity.packageDefaultDependenciesDirectory": "node_modules"
And I still get the File Import error. Any ideas?
Hi @albertov19 , those settings are by default now as node_modules has become the standard to distribute libraries. Can you post an screenshot of your project structure with the file?
Got it, I had to remove node_modules
from the settings that I had and it worked.
Thanks for this great extension!
Excellent @albertov19 :)
Thanks @albertov19, I can confirm the import via import "@openzeppelin/contracts/access/Ownable.sol"
is working when I set the solidity.packageDefaultDependenciesDirectory
to an empty string!
Maybe the issue is that I have a web app project and a contracts
subfolder in it with an own package.json
only for solidity development? This means there is a <root>/node_modules
and a <root>/contracts/node_modules
folder as well..
@ColdDevil yes that will be an issue, on discovering the node_modules, i might need to add a full path setting to allow workspaces to set their own environment
Hey, I'm still getting the "File import callback not supported" error for Openzeppelin deps despite trying all the following and more:
node_modules
directory in packageDefaultDependenciesDirectory
node_modules
from packageDefaultDependenciesDirectory
contracts
from packageDefaultDependenciesContractsDirectory
I suspect its due to the fact that I'm using the workspace feature in VS code. I have this monorepo, and each project within the monorepo is loaded as a workspace folder in VS code.
Specifically, our ethereum contracts are loaded into VS-code using this workspace folder configuration:
{
"folders": [
{
"name": "ethereum",
"path": "polkadot-ethereum/ethereum"
},
// and more
]
}
We could make the plugin run the solidity specifications from the current development environment ( truffle or hardhat .config files for instance ), and use the /node_module of the current project as the packagesPath. This way, we can keep things simple. What do you think?
@natanloterio no that will add dependencies that will be required to be extended for every other new toolset, like dapptools, or even openzeppelin etc. That will be a maintenance nightmare. What it will be ideal is to have A standard for a project file.
Edit: As of now the Oz are the default ones as it is more popular.
Closing this as it is solved, other suggestions can be put in another issue.
@vgeddes did you ever figure out a solution for your setup? We're using workspaces as well and continue to have this problem. (ie. the solutions above aren't working)
@mpaler workspaces are supported now, although in a solution they all carry the same settings. So if you are using oz, your node_modules should be at the route of each workspace.
@mpaler if you post a shot of your current workspace(s) structure and settings it might be able to understand the issue.
Hi @juanfranblanco
@openzeppelin is in packages/hardhat/node_modules
Thank you! Michael
In that scenario you could set a path to packages/hardhat/nodemodules
or the root will work with the default node_modules
either will to have the oz packages npm installed (stating the obvious)
@juanfranblanco the following solved it for me:
"solidity.packageDefaultDependenciesDirectory": "packages/hardhat/node_modules",
ah great! I guess the one at root may not have had the open zeppelin, but this matches better your project structure.
Hi, I'm following the OpenZeppelin Developing Smart Contracts "Learn" tutorial, using VSC, and all works fine but I can't seem to resolve a "problem" reported by VSC in connection with a line of code that imports "@openzeppelin/contracts/access/Ownable.sol".
VSC identifies the problem as "Source '@openzeppelin/contracts/access/Ownable.sol' not found: File import callback not supported".
Does anyone know why I get this "problem" and how to resolve it? Those @openzeppelin/contracts/access .sol files are all in my Learn directory, so why is VSC reporting otherwise?
I'm using Truffle.
I've already tried switching the default workspace compiler and modifying the package.json file in the juanblanco.solidity extension but neither change resolves anything.
I'm just reverting my solidity extensions to 0.0135 and it worked for me you can try another another version and you'll see I'm using HardHat by the way
@DrTenma1998 the extension defaults to node_modules as the main package folder. Do you have a remappings.txt file?
@DrTenma1998 this is a new project just added open zeppelin modules
hey @juanfranblanco I'm also getting this same error , can you pls help me too.
here is my project structure:
When importing from OpenZeppelin Contracts installed via npm the default settings of the plugin give a compiler error.
File import callback not supported
It would be great if importing OpenZeppelin Contracts could be supported with default settings.
The default settings include:
Users need to change the setting from
contracts
to anempty
string.Example contract with OpenZeppelin Contracts installed (
npm i @openzeppelin/contracts
)