Truffle: Compilation crashes when using truffle API (v5.1.45?)

Created on 18 Sep 2020  ·  9Comments  ·  Source: trufflesuite/truffle

Issue

Cross-reporting from solidity-coverage 535.

The crash stack-trace:

TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
    at [repo dir]/node_modules/truffle/build/webpack:/packages/workflow-compile/utils.js:34:1
    at new Promise (<anonymous>)
    at [repo dir]/node_modules/truffle/build/webpack:/packages/workflow-compile/utils.js:27:1
    at [repo dir]/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:101:1
    at Array.map (<anonymous>)
    at Object.compileSources ([repo dir]/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:91:1)
    at Object.compile ([repo dir]/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:54:1)
    at plugin ([repo dir]/node_modules/solidity-coverage/plugins/truffle.plugin.js:101:29)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.1.45 (core: 5.1.45)
Node v12.18.4

The code at solidity-coverage is +/-:

const truffle = require('truffle'); 
await truffle.contracts.compile(config);

Prior to 8c5555e798cf1eb17d0d76d8e737e6bfc0abd032 require('truffle').contracts was equivalent to require('@truffle/workflow-compile')
...since then it's been bound to @truffle/workflow-compile/legacy.

Happy to update solidity-coverage to use a new API if exposed fwiw. 🙂

Environment

  • Operating System:
  • Ethereum client: Ganache
  • Truffle version (truffle version): 5.1.45 (may affect earlier versions too...)
  • node version (node --version): 12
  • npm version (npm --version):

All 9 comments

Oh whoops, sorry @cgewecke. Looks like there was an oversight involving the integration of the legacy package with external-compile and compile-vyper. We'll try and have a patch out next week!

By the way, if you happen to have something I can verify against once I have a fix then let me know. I'll test and make sure it is behaving as desired before we release.

@eggplantzzz

Not certain how to write a test for it at Truffle but

mkdir repro && cd repro
npm init --yes
npm install --save-dev solidity-coverage
truffle unbox metacoin

...then update truffle-config.js with

module.exports = {
  plugins: ['solidity-coverage']
};

and run

npx truffle run coverage

produces:

Users-MacBook-Air:t-sol cgewecke$ npx truffle run coverage

> Using Truffle library from local node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.1.45
> ganache-core:      v2.11.2
> solidity-coverage: v0.7.10

Network Info
============
> id:      *
> port:    8555
> network: soliditycoverage


Instrumenting for coverage...
=============================

> ConvertLib.sol
> MetaCoin.sol

Coverage skipped for:
=====================

> Migrations.sol

Compiling your contracts...
===========================
> solidity-coverage cleaning up, shutting down ganache server
TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
    at /Users/cgewecke/code/t-sol/node_modules/truffle/build/webpack:/packages/workflow-compile/utils.js:34:1
    at new Promise (<anonymous>)
    at /Users/cgewecke/code/t-sol/node_modules/truffle/build/webpack:/packages/workflow-compile/utils.js:27:1
    at /Users/cgewecke/code/t-sol/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:101:1
    at Array.map (<anonymous>)
    at Object.compileSources (/Users/cgewecke/code/t-sol/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:91:1)
    at Object.compile (/Users/cgewecke/code/t-sol/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:54:1)
    at plugin (/Users/cgewecke/code/t-sol/node_modules/solidity-coverage/plugins/truffle.plugin.js:101:29)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.1.45 (core: 5.1.45)
Node v12.16.0

Thanks @cgewecke! I just wanted to have one more way to verify the fix. Do note, however, that we did create a new interface for @truffle/workflow-compile and the one being exposed in @truffle/core is now legacy. You might consider upgrading though we don't expose it in @truffle/core. Unfortunately we don't have docs for it (I'll try and work on that too) yet but there are types in compile-common/src/types you might find helpful. We won't remove the legacy stuff until v6, so of course so there is no rush to change anything really :)

I'll keep you posted about the fix!

@eggplantzzz Ah good to know. Thanks so much!

@cgewecke I think I have a fix for you. I published it under truffle@cgewecke. If you have time to check and verify that the issue was fixed I would appreciate it! Then we should be able to release it with our regular release this week.

@eggplantzzz Looks good on my end! Thanks so much

Users-MacBook-Air:t-sol cgewecke$ npx truffle run coverage

> Using Truffle library from local node_modules.

> server:            http://127.0.0.1:8555
> truffle:           v5.1.46-alpha.0
> ganache-core:      v2.11.2
> solidity-coverage: v0.7.10

Network Info
============
> id:      *
> port:    8555
> network: soliditycoverage


Instrumenting for coverage...
=============================

> ConvertLib.sol
> MetaCoin.sol

Coverage skipped for:
=====================

> Migrations.sol

Compiling your contracts...
===========================
> Compiling ./.coverage_contracts/ConvertLib.sol
> Compiling ./.coverage_contracts/MetaCoin.sol
> Compiling ./.coverage_contracts/Migrations.sol
> Artifacts written to /Users/cgewecke/code/t-sol/.coverage_artifacts/contracts
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

⚠️  This plugin cannot run Truffle's native solidity tests: 1 test(s) will be skipped.


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



  Contract: MetaCoin
    ✓ should put 10000 MetaCoin in the first account (48ms)
    ✓ should call a function that depends on a linked library (97ms)
    ✓ should send coin correctly (234ms)


  3 passing (444ms)

-----------------|----------|----------|----------|----------|----------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------|----------|----------|----------|----------|----------------|
 contracts/      |       90 |       50 |      100 |      100 |                |
  ConvertLib.sol |      100 |      100 |      100 |      100 |                |
  MetaCoin.sol   |    88.89 |       50 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|
All files        |       90 |       50 |      100 |      100 |                |
-----------------|----------|----------|----------|----------|----------------|

> Istanbul reports written to ./coverage/ and ./coverage.json
> solidity-coverage cleaning up, shutting down ganache server

Thanks so much for verifying for me! Sorry I broke it to begin with!

5.1.46 is working for me 🙂

Thanks!!

Was this page helpful?
0 / 5 - 0 ratings