在松露迁移中不支持文件导入回调



我有一个松露项目,有以下合同(省略),我正在运行松露迁移:

1 pragma solidity >=0.6.0;
2
3 // implements the ERC721 standard
4 import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5 // keeps track of the number of tokens issued
6 import "@openzeppelin/contracts/utils/Counters.sol";
7 import "@openzeppelin/contracts/access/Ownable.sol";

但是我得到以下错误:

> Compiling ./contracts/NFT.sol
> Compilation warnings encountered:
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> project:/contracts/Creation.sol

ParserError: Source "@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported
--> project:/contracts/NFT.sol:6:1:
|
6 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
,ParserError: Source "@openzeppelin/contracts/utils/Counters.sol" not found: File import callback not supported
--> project:/contracts/NFT.sol:8:1:
|
8 | import "@openzeppelin/contracts/utils/Counters.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
,ParserError: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported
--> project:/contracts/NFT.sol:9:1:
|
9 | import "@openzeppelin/contracts/access/Ownable.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed. See above.
Truffle v5.4.0 (core: 5.4.0)
Node v14.15.5

如何修复这个错误?

即使我的合同工作,我有同样的错误…我刚修改了:

import "@openzeppelin/contracts/utils/Counters.sol"; 

到更明确的形式:

import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";

绕过那些红色的弯弯曲曲

您是否运行了以下命令

$ npm init
$ npm i -s @openzeppelin/contracts

最新更新