Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG : problem of library import #6

Open
PhilippeR26 opened this issue May 28, 2024 · 4 comments
Open

BUG : problem of library import #6

PhilippeR26 opened this issue May 28, 2024 · 4 comments

Comments

@PhilippeR26
Copy link

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

  • create a TS script, including :
import { WALLET_API } from "starknet-types";
  • using this package.json :
{
  "name": "starknet-js-typescript",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest",
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "starknet": "6.9.0",
    "starknet-merkle-tree": "^1.0.2",
    "starknet-types": "^0.7.2",
  },
  "devDependencies": {
    "ts-node": "^10.9.2",
    "typescript": "^5.3.3"
  }
}
  • and this tsconfig.json :
{
  "compilerOptions": {
    "target":"ES2022",
    "lib": [
      "es2022",
      "dom"
    ],
    "outDir": "./out",
    "rootDir": "./src",
    "incremental": true,
    "module": "Node16",
    "moduleResolution": "Node16",
    "resolveJsonModule": true,
    "strict": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "isolatedModules": true,
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}
  • try to compile
ts-node ./script.ts

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

Screenshots
N/A

Desktop (please complete the following information):

  • Browser & version [e.g. chrome, safari, webworker] : any
  • Node version [e.g. 16.0.1] : [email protected]
  • library version : 0.7.2

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

@tabaktoni
Copy link
Collaborator

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
Copy link
Author

@tabaktoni
Copy link
Collaborator

Link is deprecated, can we close this one ?

@PhilippeR26
Copy link
Author

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

No branches or pull requests

2 participants