graphprotocol / contracts

Contracts repository for The Graph protocol

Home Page:https://thegraph.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors when trying NPM publish

tmigone opened this issue · comments

When running npm publish --access public getting two errors:

  1. Missing ABI folder --> Fixed by running hh export-abi in the prepublish script
  2. esModuleInterop error below
tomi@ceres:/U/t/Doc/g/th/contracts (dev) ✗ npm publish --access public

> @graphprotocol/contracts@1.14.0-testnet-product prepublishOnly
> scripts/prepublish

yarn run v1.22.19
$ rm -rf build/ cache/ dist/
✨  Done in 0.07s.
yarn run v1.22.19
$ SKIP_LOAD=true scripts/build
$ hardhat compile
...

Generating typings for: 94 artifacts in dir: build/types for target: ethers-v5
Successfully generated 151 typings!
Compiled 91 Solidity files successfully
✨  Done in 14.00s.
Nothing to compile
No need to generate any newer typings.
node_modules/hardhat/node_modules/ethereumjs-util/dist/externals.d.ts:6:8 - error TS1259: Module '"/Users/tomi/Documents
/git/thegraph/contracts/node_modules/@types/bn.js/index"' can only be default-imported using the 'esModuleInterop' flag

6 import BN from 'bn.js';
         ~~

  node_modules/@types/bn.js/index.d.ts:594:1
    594 export = BN;
        ~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleIn
terop' flag.

node_modules/rlp/dist/types.d.ts:2:8 - error TS1259: Module '"/Users/tomi/Documents/git/thegraph/contracts/node_modules/
@types/bn.js/index"' can only be default-imported using the 'esModuleInterop' flag

2 import BN from 'bn.js';
         ~~

  node_modules/@types/bn.js/index.d.ts:594:1
    594 export = BN;
        ~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleIn
terop' flag.


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/hardhat/node_modules/ethereumjs-util/dist/externals.d.ts:6
     1  node_modules/rlp/dist/types.d.ts:2
npm ERR! code 2
npm ERR! path /Users/tomi/Documents/git/thegraph/contracts
npm ERR! command failed
npm ERR! command sh -c scripts/prepublish

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tomi/.npm/_logs/2022-07-25T09_24_14_879Z-debug-0.log

This seems to have broken with the latest version of Hardhat.

Instead of calling the export-abi command in the prepublish I'd do this in the hardhat.config.ts:

  abiExporter: {
    path: './build/abis',
    clear: true,
    flat: true,
    runOnCompile: true,
  },