starknet-io / types-js

MIT License
7 stars 4 forks source link

BUG : problem of library import #6

Open PhilippeR26 opened 3 months ago

PhilippeR26 commented 3 months ago

Describe the bug When using this lib in ts-node, I have a compilation message error :

TSError: ⨯ Unable to compile TypeScript:
src/tmp/26.testSepolia.ts:12:28 - error TS1479: 
The current file is a CommonJS module whose imports will produce 'require' calls; 
however, the referenced file is an ECMAScript module and cannot be imported with 'require'. 
Consider writing a dynamic 'import("starknet-types")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', 
or add the field `"type": "module"` to '/home/edmond/Documents/starknet/starknet.js-workshop-typescript/package.json'.

12 import { WALLET_API } from "starknet-types";
                              ~~~~~~~~~~~~~~~~

To Reproduce

Expected behavior Use of this library with my project config, without compilation error.

Screenshots N/A

Desktop (please complete the following information):

Additional context I am using this project config for a long time, without any problem on many libraries, except this one.

tabaktoni commented 3 months ago

The issue is that your bundle project is CommonJS so you can switch to new es-module or you can use type import: import type { SomeWalletApiType } from '@starknet-io/types-js' maybe you will need to use "moduleResolution": "Bundler" if you stay on Commonjs. This is not strictly a ts-types issue but I can do an example on your project if you still have this issue? so that others can copy the solution.

PhilippeR26 commented 3 months ago

A script that handles the problem : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/Starknet131/Starknet131-sepolia/2.testZeroable.ts

tabaktoni commented 3 months ago

Link is deprecated, can we close this one ?

PhilippeR26 commented 3 months ago

Unfortunately the problem is still there : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/Starknet131/Starknet131-devnet/10.testZeroable.ts