ethcall icon indicating copy to clipboard operation
ethcall copied to clipboard

getting importAssertions error

Open 5war00p opened this issue 1 year ago • 4 comments

As ethcall is using assert keyword inside lib/call.js and lib/calls.js to import ABI's. Using ethcall in typescript project giving importAssertions error. It's a CRA which is customized using react-app-rewired

image The solution is suggested in the error itself, which is adding a Babel plugin called @babel/plugin-syntax-import-assertions

Or are there any other solutions for this?

5war00p avatar May 25 '23 12:05 5war00p

Hey @5war00p, thanks for bringing this up. I added a note in README about it. Can't say much about CRA support unfortunately. It's known to work in Vite 4+ and Rollup 3+, can't say much outside that.

Destiner avatar Jun 07 '23 19:06 Destiner

Do you think adding the Babel config for importAssertions into the project would work? using below package

npm install --save-dev @babel/plugin-syntax-import-assertions

Refernce: https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-assertions

5war00p avatar Jun 07 '23 20:06 5war00p

Hmm, that would also require adding babel as dependency?

Destiner avatar Jun 07 '23 22:06 Destiner

Yes. But there is another approach to solve this issue.

I followed the error messages and updated tsconfig of the tsc compiler to the below and it's executed without throwing errors.

{
  "compilerOptions": {
    "target": "es2015",
    "module": "esnext",
    "moduleResolution": "nodenext",
    "resolveJsonModule": true
   }
}

image

Anyway current target is "ES2020", so that is not the issue, updating moduleResolution to nodenext solved this issue.

As the typescript version in the package is >4.7 we should be using node16 or nodenext. Reference:

  1. https://www.typescriptlang.org/tsconfig#moduleResolution
  2. https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs

5war00p avatar Jun 08 '23 04:06 5war00p