Giter Site home page Giter Site logo

Comments (6)

sharifzadesina avatar sharifzadesina commented on August 16, 2024

It is possible to import types like this:

import type { Transaction as TronTransaction } from "tronweb/lib/esm/types/Transaction.js";
import type { TransferContract, TriggerSmartContract } from "tronweb/lib/esm/types/Contract.js";
import type { Block as TronBlock } from "tronweb/lib/esm/types/APIResponse.js";

But when you try to import ContractType, because it is not a type, we get an error:

import { ContractType } from "tronweb/lib/esm/types/Contract.js";

console.log(ContractType.AccountCreateContract);

The code above fails with error:

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/esm/types/Contract.js' is not defined by "exports" in /home/sina/Projects/pouch-js/node_modules/tronweb/package.json imported from /home/sina/Projects/pouch-js/src/test.ts
    at new NodeError (node:internal/errors:406:5)
    at exportsNotFound (node:internal/modules/esm/resolve:268:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:598:9)
    at packageResolve (node:internal/modules/esm/resolve:772:14)
    at moduleResolve (node:internal/modules/esm/resolve:838:20)
    at defaultResolve (node:internal/modules/esm/resolve:1043:11)
    at nextResolve (node:internal/modules/esm/hooks:833:28)
    at h (file:///home/sina/Projects/pouch-js/node_modules/tsx/dist/esm/index.mjs?1716925776637:2:1939)
    at j (file:///home/sina/Projects/pouch-js/node_modules/tsx/dist/esm/index.mjs?1716925776637:2:3184)
    at async nextResolve (node:internal/modules/esm/hooks:833:22) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v20.8.1

from tronweb.

start940315 avatar start940315 commented on August 16, 2024

Because ContractType is an enum type and if you import it without type key word, it will generate the import statement in the output file. But we don't add this subpath in our package.json as we did't know that anyone will use this object. We are consider to add this subpath in our next version. For now, you can copy the code in the file and use it.

from tronweb.

zachariahevans174 avatar zachariahevans174 commented on August 16, 2024

from tronweb.

sharifzadesina avatar sharifzadesina commented on August 16, 2024

@start940315 Of course it is not a type, so it throws an error. please on the next update export types also.

from tronweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.