ethcall
ethcall copied to clipboard
getting importAssertions error
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
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?
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.
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
Hmm, that would also require adding babel as dependency?
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
}
}
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:
- https://www.typescriptlang.org/tsconfig#moduleResolution
- https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs