File import callback not supported - Linux - Crowdsale contract

UPDATE: TDLR

maybe yarn add openzepplin-v5@npm:@openzeppelin/contracts@2.5.1 was not the right thing to do ??

(Still the stupid red lines show up in VScode … )

=========================================================================

During my development I suddenly got the imports underlined in red in VScode, but compiling still worked.

Then I wanted to create a simple crowd sale and tought it might be a good idea to have it in a separate project as it need the v2 contracts while my project is using already v3 contract.

So, to avoid possible confusion I created a new blank truffle project, and npm init, selected even in VScode solc 0.5.16/17 , but now I have the same problem again and on top of that, even compiling on the Linux command line does not work any more.
What could be wrong ???

$ truffle compile
Warning: Both truffle-config.js and truffle.js were found. Using truffle-config.js.

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/TicketCrowdsale.sol

CompileError: /home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/contracts/TicketCrowdsale.sol:9:1: ParserError: Source "@openzeppelin/contracts/crowdsale/Crowdsale.sol" not found: File import callback not supported
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
^-------------------------------------------------------^
,/home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/contracts/TicketCrowdsale.sol:10:1: ParserError: Source "@openzeppelin/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol" not found: File import callback not supported
import "@openzeppelin/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol";
^------------------------------------------------------------------------------------^
,/home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/contracts/TicketCrowdsale.sol:11:1: ParserError: Source "@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol" not found: File import callback not supported
import "@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol";
^-----------------------------------------------------------------------^

Compilation failed. See above.
    at run (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/run.js:53:1)
    at Object.sourcesWithDependencies (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/index.js:121:58)
    at necessary (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/index.js:72:1)
    at /home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:33:1
    at async Promise.all (index 0)
    at compile (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:23:1)
    at Object.compile (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:66:45)
    at Object.run (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/compile.js:86:1)
    at Command.run (/home/sum/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
Truffle v5.1.64 (core: 5.1.64)
Node v12.19.0
[sum@XPS15 ticket-crowdsale]$ truffle version
Warning: Both truffle-config.js and truffle.js were found. Using truffle-config.js.
Truffle v5.1.64 (core: 5.1.64)
Solidity v0.5.16 (solc-js)
Node v12.19.0
Web3.js v1.2.9

1 Like

I just created a new project using hardhat, following along the tutorial

… and it worked without any problems.

So maybe a truffle problem … ?
I always upgrade truffle weekly, so maybe a problem with the last version ?

2 Likes

Maybe I also mixed usage of yarn and npm (too much up).

going back a few truffle version changes the error message (which I find better to understand)

$ npm uninstall -g truffle
$ npm install truffle@5.1.60

$ npx truffle compile
Warning: Both truffle-config.js and truffle.js were found. Using truffle-config.js.

Compiling your contracts...
===========================
Error: Could not find @openzeppelin/contracts/crowdsale/Crowdsale.sol from any sources; imported from /home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/contracts/TicketCrowdsale.sol
    at Resolver.<anonymous> (/home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/node_modules/truffle/build/webpack:/packages/resolver/dist/lib/resolver.js:62:1)
    at Generator.next (<anonymous>)
    at fulfilled (/home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/node_modules/truffle/build/webpack:/packages/resolver/dist/lib/resolver.js:5:42)
Truffle v5.1.60 (core: 5.1.60)
Node v12.19.0

Maybe I should not have added contract v2.5.1 using the yarn add from another post?

$ npm list --depth=1 | grep openz
β”œβ”€β”€ UNMET DEPENDENCY openzepplin-v5@npm:@openzeppelin/contracts@2.5.1
npm ERR! missing: openzepplin-v5@npm:@openzeppelin/contracts@2.5.1, required by ticket-crowdsale@0.5.0

Adding it the plain way works …

$ npm install @openzeppelin/contracts@2.5.1
npm WARN ticket-crowdsale@0.5.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ @openzeppelin/contracts@2.5.1
added 1 package from 1 contributor and audited 145 packages in 2.973s

37 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

[sum@XPS15 ticket-crowdsale]$ npm list --depth=1 | grep openz
β”œβ”€β”€ @openzeppelin/contracts@2.5.1
β”œβ”€β”€ UNMET DEPENDENCY openzepplin-v5@npm:@openzeppelin/contracts@2.5.1
npm ERR! missing: openzepplin-v5@npm:@openzeppelin/contracts@2.5.1, required by ticket-crowdsale@0.5.0
[sum@XPS15 ticket-crowdsale]$ npx truffle compile
Warning: Both truffle-config.js and truffle.js were found. Using truffle-config.js.

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/TicketCrowdsale.sol
> Compiling @openzeppelin/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts/access/Roles.sol
> Compiling @openzeppelin/contracts/access/roles/CapperRole.sol
> Compiling @openzeppelin/contracts/crowdsale/Crowdsale.sol
> Compiling @openzeppelin/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol
> Compiling @openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol
> Compiling @openzeppelin/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/SafeERC20.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Compiling @openzeppelin/contracts/utils/ReentrancyGuard.sol
> Artifacts written to /home/sum/DEV/ETH/ZeroSwap/ticket-crowdsale/build/contracts
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

1 Like

@abcoathup sorry for the long post , I just might not have handled yarn and npm correctly.
Which one should I use?
Should I really do not mix them?
… or can I start with npm, then mpve to yarn, as long as I do not go back ???

At least it mode obvious that the width restriction of the post here does not really make sense, as soon as there are some longer lines, the code ends up in a box and you have to move the vertical scroll back back and forth to be able to read something … maybe this could just be β€œas wide as the screen window is” ?

1 Like

Hi @sven.meyer,

I don’t think it is recommended to mix yarn and npm as you will end up with lock files from both yarn and npm and could cause issues. You should pick one and stick to it.

I assume when you created the alias in yarn, you would need to use the alias in your import statements so that they could be found in node_modules.

Unfortunately for formatting we are likely restricted to Discourse.