Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

getting importAssertions error #196

Open
5war00p opened this issue May 25, 2023 · 4 comments
Open

getting importAssertions error #196

5war00p opened this issue May 25, 2023 · 4 comments

Comments

@5war00p
Copy link

5war00p commented May 25, 2023

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?

@Destiner
Copy link
Owner

Destiner commented Jun 7, 2023

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.

@5war00p
Copy link
Author

5war00p commented Jun 7, 2023

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

@Destiner
Copy link
Owner

Destiner commented Jun 7, 2023

Hmm, that would also require adding babel as dependency?

@5war00p
Copy link
Author

5war00p commented Jun 8, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants