【问题标题】:File import callback not supported on truffle migrate松露迁移不支持文件导入回调
【发布时间】:2021-08-01 07:20:34
【问题描述】:

我有一个 truffle 项目,我使用 truffle migrate 运行以下合同(省略):

    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

如何解决这个错误?

【问题讨论】:

    标签: ethereum solidity truffle


    【解决方案1】:

    你跑了吗

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

    【讨论】:

      【解决方案2】:

      即使我的合同有效,我也有同样的错误......我只是改变了:

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

      更明确的形式:

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

      绕过那些红色曲线。

      【讨论】:

        猜你喜欢
        • 2021-07-23
        • 1970-01-01
        • 1970-01-01
        • 2021-05-04
        • 2021-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-05
        相关资源
        最近更新 更多