-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contracts in NPM @org/dep scoped dependencies don't resolve #160
Comments
@cag can you post a sample of your code and project structure including dependencies thanks |
I have actually seen the issue now on Macs, I'm investigating |
@cag I have tested this in Linux, Mac and Windows.. and I have reproduced it, although eventually just changing the settings and restarting vscode has solved the issue. |
Any workaround for this? Changing the settings and restarting isn't fixing it for me. :( |
@chanhosuh what settings are you using? |
@juanfranblanco here are my extension-specific settings... I put them both into user and workspace settings.
Let me know if anything else would be helpful. I tried multiple versions going back more than a year, and the problem seems to persist. Interestingly, only the latest versions show red marks around the import; the earlier versions error on the import but do not show the red. |
And your imports? you may need to remove the "contracts" from packageDefaultDependenciesContractsDirectory and use "" instead. |
imports are:
But... your advice of removing "contracts" worked! :). So strange. |
Yeah mainly that setting is to remove the need to write "contracts" in the import path. |
I am getting an error with for where with settings
Obviously I don't have these set correctly, but its quite unclear how to set these. Any tips? |
@deluca-mike sorry I have just seen this you should have "solidity.packageDefaultDependenciesDirectory": "node_modules" as the dependencies directory |
@talentlessguy This is not an issue normally as it is also the default, the only thing I can think is that your node_modules in the root folder. |
@juanfranblanco my node_modules is in the root. I tried with pnpm, npm and yarn. None worked :( |
@talentlessguy super strange. This is an example structure: Edit: My settings are the global / default ones for those, you might have overridden them in your workspace? |
@juanfranblanco nope I have them set globally and have no if this helps, this is my contract code: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract MyNFT is ERC721, Ownable {
struct Metadata {
string title;
string picture;
string audio;
}
event Mint(Metadata metadata);
event Claim(uint256 id);
uint256 public constant MAX_TOKENS = 50;
uint256 private constant PRICE = 50000000000000000;
bool private _isSaleActive = true;
using SafeMath for uint256;
mapping(uint256 => Metadata) id_to_nft;
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyNFT", "MNFT") {}
// Mint NFT and increment ID
function safeMint(address to) public onlyOwner {
uint256 id = _tokenIdCounter.current();
_safeMint(to, id);
_tokenIdCounter.increment();
}
function _baseURI() internal pure override returns (string memory) {
return ;
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721)
returns (string memory)
{
return super.tokenURI(tokenId);
}
// Mint an NFT and add metadata to it
function mint(
string memory title,
string memory picture,
string memory audio
) public onlyOwner returns (uint256) {
uint256 tokenId = _tokenIdCounter.current();
Metadata memory metadata = Metadata(title, picture, audio);
id_to_nft[tokenId] = metadata;
safeMint(msg.sender);
emit Mint(metadata);
return tokenId;
}
// Claim and mint NFT
function claim(uint256 id) external payable {
require(msg.value == PRICE, "Claiming an NFT costs 0.05 ETH");
require(_tokenIdCounter.current() <= MAX_TOKENS, "Sold out!");
// Transfer to seller
safeTransferFrom(address(this), msg.sender, id);
emit Claim(id);
}
// Toggle sale mode
function toggleSale() public onlyOwner returns (bool) {
_isSaleActive = !_isSaleActive;
return _isSaleActive;
}
// Check if sale is active
function isSaleActive() public view returns (bool) {
return _isSaleActive;
}
// withdraw bobux
function withdraw() public onlyOwner {
uint256 balance = address(this).balance;
payable(msg.sender).transfer(balance);
}
function transferTo(address acc, uint256 id) public onlyOwner {
safeTransferFrom(msg.sender, acc, id);
}
}
|
Check this: |
@talentlessguy ^^^ |
@juanfranblanco thanks, testing right now could the issue be that my contracts in the |
No that should not be an issue, i have included the workspace settings to override the global just in case. |
@talentlessguy although you shouldn't, have you tried to restart it? |
@juanfranblanco i found it out. it didn't work when i have it in a workspace with multiple projects. when opening directly it works. but it should work for multiple projects in a workspace imo thanks tho |
@talentlessguy thanks, yes it does not work with multiple workspaces, those were introduced much later, so it will break a lot of stuff, I think project files will be the way forward. But that requires to everyone agree to the format. |
I have the same issue: package.json:
Settings: |
Thanks for this, have you got any remappings? |
I have
in my settings and am trying to import contracts from a scoped package, but am getting an error:
Source "@org/dep/contracts/Dependency.sol" not found: File import callback not supported
The text was updated successfully, but these errors were encountered: