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

Typescript compile error #4542

Closed
1 task done
crazyoptimist opened this issue Nov 15, 2021 · 2 comments
Closed
1 task done

Typescript compile error #4542

crazyoptimist opened this issue Nov 15, 2021 · 2 comments
Labels
Bug Addressing a bug

Comments

@crazyoptimist
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

It's a very simple code (a nest.js service) using opensea.io sdk.

import { Injectable } from '@nestjs/common';
import Web3 from 'web3';
import { OpenSeaPort, Network } from 'opensea-js';
import { OpenSeaAsset } from 'opensea-js/lib/types';

const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io');

const seaport = new OpenSeaPort(provider, {
  networkName: Network.Main,
});

const tokenAddress = '0x06012c8cf97bead5deae237070f9587f8e7a266d';
const tokenId = '1';

@Injectable()
export class OpenseaService {
  async fetchTrendingAssets() {
    const asset: OpenSeaAsset = await seaport.api.getAsset({
      tokenAddress,
      tokenId,
    });
    return asset;
  }
}

It runs by ts-node -r tsconfig-paths/register src/main.ts.
But it stuck when building by tsc.
Here's the terminal log I'm seeing:

yarn run v1.22.17
$ rm -rf dist && tsc
node_modules/@0xproject/types/lib/index.d.ts:23:16 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntry'.

23     logs: Web3.LogEntry[];
                  ~~~~~~~~

node_modules/@0xproject/types/lib/index.d.ts:39:60 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'DecodedLogEntry'.

39 export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {
                                                              ~~~~~~~~~~~~~~~

node_modules/@0xproject/types/lib/index.d.ts:41:35 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntry'.

41 export declare type RawLog = Web3.LogEntry;
                                     ~~~~~~~~

node_modules/@0xproject/types/lib/index.d.ts:49:59 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntry'.

49     logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>;
                                                             ~~~~~~~~

node_modules/opensea-js/lib/seaport.d.ts:7:11 - error TS2709: Cannot use namespace 'Web3' as a type.

7     web3: Web3;
            ~~~~

node_modules/opensea-js/lib/seaport.d.ts:8:19 - error TS2709: Cannot use namespace 'Web3' as a type.

8     web3ReadOnly: Web3;
                    ~~~~

node_modules/opensea-js/lib/seaport.d.ts:29:32 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'Provider'.

29     constructor(provider: Web3.Provider, apiConfig?: OpenSeaAPIConfig, logger?: (arg: string) => void);
                                  ~~~~~~~~

node_modules/opensea-js/lib/types.d.ts:498:57 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'JSONRPCResponsePayload'.

498 export declare type Web3RPCCallback = Web3Callback<Web3.JSONRPCResponsePayload>;
                                                            ~~~~~~~~~~~~~~~~~~~~~~

node_modules/opensea-js/lib/types.d.ts:504:16 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'AbiType'.

504     type: Web3.AbiType | string;
                   ~~~~~~~

node_modules/opensea-js/lib/types.d.ts:511:28 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ConstructorStateMutability'.

511     stateMutability?: Web3.ConstructorStateMutability | string;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:19:49 - error TS2709: Cannot use namespace 'Web3' as a type.

19 export declare const confirmTransaction: (web3: Web3, txHash: string) => Promise<unknown>;
                                                   ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:42:49 - error TS2709: Cannot use namespace 'Web3' as a type.

42 export declare function personalSignAsync(web3: Web3, message: string, signerAddress: string): Promise<ECSignature>;
                                                   ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:48:49 - error TS2709: Cannot use namespace 'Web3' as a type.

48 export declare function isContractAddress(web3: Web3, address: string): Promise<boolean>;
                                                   ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:65:50 - error TS2709: Cannot use namespace 'Web3' as a type.

65 export declare function sendRawTransaction(web3: Web3, { from, to, data, gasPrice, value, gas }: Web3.TxData, onError: (error: Error) => void): Promise<string>;
                                                    ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:65:103 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'TxData'.

65 export declare function sendRawTransaction(web3: Web3, { from, to, data, gasPrice, value, gas }: Web3.TxData, onError: (error: Error) => void): Promise<string>;
                                                                                                         ~~~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:76:39 - error TS2709: Cannot use namespace 'Web3' as a type.

76 export declare function rawCall(web3: Web3, { from, to, data }: Web3.CallData, onError?: (error: Error) => void): Promise<string>;
                                         ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:76:70 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'CallData'.

76 export declare function rawCall(web3: Web3, { from, to, data }: Web3.CallData, onError?: (error: Error) => void): Promise<string>;
                                                                        ~~~~~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:85:43 - error TS2709: Cannot use namespace 'Web3' as a type.

85 export declare function estimateGas(web3: Web3, { from, to, data, value }: Web3.TxData): Promise<number>;
                                             ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:85:81 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'TxData'.

85 export declare function estimateGas(web3: Web3, { from, to, data, value }: Web3.TxData): Promise<number>;
                                                                                   ~~~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:90:50 - error TS2709: Cannot use namespace 'Web3' as a type.

90 export declare function getCurrentGasPrice(web3: Web3): Promise<BigNumber>;
                                                    ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:96:54 - error TS2709: Cannot use namespace 'Web3' as a type.

96 export declare function getTransferFeeSettings(web3: Web3, { asset, accountAddress }: {
                                                        ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:151:62 - error TS2709: Cannot use namespace 'Web3' as a type.

151 export declare function validateAndFormatWalletAddress(web3: Web3, address: string): string;
                                                                 ~~~~

node_modules/opensea-js/lib/utils/utils.d.ts:161:77 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

161 export declare function getNonCompliantApprovalAddress(erc721Contract: Web3.ContractInstance, tokenId: string, accountAddress: string): Promise<string | undefined>;
                                                                                ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/base_contract.d.ts:4:42 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

4     protected web3ContractInstance: Web3.ContractInstance;
                                           ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/base_contract.d.ts:7:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

7     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                             ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/wyvern_atomicizer.d.ts:15:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

15     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                              ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/wyvern_d_a_o.d.ts:102:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

102     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                               ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/wyvern_exchange.d.ts:128:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

128     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                               ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/wyvern_proxy_registry.d.ts:69:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

69     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                              ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/abi_gen/wyvern_token.d.ts:110:44 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'ContractInstance'.

110     constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>);
                                               ~~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/types.d.ts:47:37 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntryEvent'.

47 export declare type LogEvent = Web3.LogEntryEvent;
                                       ~~~~~~~~~~~~~

node_modules/wyvern-js/lib/types.d.ts:56:60 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'DecodedLogEntry'.

56 export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {
                                                              ~~~~~~~~~~~~~~~

node_modules/wyvern-js/lib/types.d.ts:59:59 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntry'.

59     logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>;
                                                             ~~~~~~~~

node_modules/wyvern-js/lib/types.d.ts:71:35 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'LogEntry'.

71 export declare type RawLog = Web3.LogEntry;
                                     ~~~~~~~~

node_modules/wyvern-js/lib/types.d.ts:155:41 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'Provider'.

155 export declare type Web3Provider = Web3.Provider;
                                            ~~~~~~~~

node_modules/wyvern-schemas/dist/index.d.ts:4:10 - error TS2614: Module '"web3"' has no exported member 'AbiType'. Did you mean to use 'import AbiType from "web3"' instead?

4 export { AbiType, } from 'web3';
           ~~~~~~~

node_modules/wyvern-schemas/dist/types.d.ts:56:16 - error TS2694: Namespace '"/home/netfan/oneandzeros/node-nft-backend/node_modules/web3/types/index"' has no exported member 'AbiType'.

56     type: Web3.AbiType.Event;
                  ~~~~~~~


Found 37 errors.

error Command failed with exit code 2.

And here's my tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "paths": {
      "modules/*": ["modules/*"]
    },
    "esModuleInterop": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

Something is wrong in the tsconfig or am I missing something else?
Any help would be appreciated.

Expected Behavior

tsc should run without an error

Steps to Reproduce

Here's the code you can use for reproduce:

import { Injectable } from '@nestjs/common';
import Web3 from 'web3';
import { OpenSeaPort, Network } from 'opensea-js';
import { OpenSeaAsset } from 'opensea-js/lib/types';

const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io');

const seaport = new OpenSeaPort(provider, {
  networkName: Network.Main,
});

const tokenAddress = '0x06012c8cf97bead5deae237070f9587f8e7a266d';
const tokenId = '1';

@Injectable()
export class OpenseaService {
  async fetchTrendingAssets() {
    const asset: OpenSeaAsset = await seaport.api.getAsset({
      tokenAddress,
      tokenId,
    });
    return asset;
  }
}

Here's my tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "paths": {
      "modules/*": ["modules/*"]
    },
    "esModuleInterop": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

Web3.js Version

latest(1.6.0)

Environment

  • Operating System: Ubuntu 20.04
  • Browser: Not used
  • Node.js Version: 16.13 (same behavior with v14.17)
  • NPM Version: 8.1.0 (same with v6.4)

Anything Else?

No response

@crazyoptimist crazyoptimist added the Bug Addressing a bug label Nov 15, 2021
@crazyoptimist crazyoptimist changed the title Typescript build error Typescript compile error Nov 15, 2021
@crazyoptimist
Copy link
Author

package.json file is here:

{
  "name": "nest-starter",
  "version": "1.0.0",
  "description": "Nest.js Starter For Minimalists",
  "author": "CrazyOptimist",
  "license": "ISC",
  "scripts": {
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "nodemon",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rm -rf dist && tsc",
    "start:prod": "node -r ./tsconfig-paths-bootstrap.js dist/main.js",
    "start:hmr": "node dist/server",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:e2e": "jest --config ./test/jest-e2e.json",
    "webpack": "webpack --config webpack.config.js",
    "ts-typeorm": "ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm",
    "migration:create": "typeorm migration:create -d src/migrations",
    "migration:run": "yarn ts-typeorm migration:run",
    "migration:revert": "yarn ts-typeorm migration:revert",
    "prepare": "husky install"
  },
  "dependencies": {
    "@nestjs/common": "^7.6.5",
    "@nestjs/core": "^7.6.5",
    "@nestjs/jwt": "^7.2.0",
    "@nestjs/passport": "^7.1.5",
    "@nestjs/platform-express": "^7.6.5",
    "@nestjs/swagger": "^4.7.12",
    "@nestjs/typeorm": "^7.1.5",
    "@types/bcrypt": "^3.0.0",
    "bcrypt": "^5.0.0",
    "class-transformer": "^0.3.2",
    "class-validator": "^0.13.1",
    "dotenv": "^8.2.0",
    "lint-staged": "^11.1.2",
    "mysql": "^2.18.1",
    "opensea-js": "^1.2.1",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^6.6.3",
    "swagger-ui-express": "^4.1.6",
    "typeorm": "^0.2.30",
    "typescript": "^4.1.3",
    "web3": "^1.6.0"
  },
  "devDependencies": {
    "@nestjs/testing": "^7.6.5",
    "@types/jest": "^26.0.20",
    "@types/node": "^14.14.22",
    "@types/supertest": "^2.0.10",
    "@types/swagger-ui-express": "^4.1.2",
    "@typescript-eslint/eslint-plugin": "^4.14.0",
    "@typescript-eslint/parser": "^4.14.0",
    "eslint": "^7.18.0",
    "husky": "^7.0.0",
    "jest": "^26.6.3",
    "nodemon": "^2.0.7",
    "prettier": "^2.2.1",
    "supertest": "6.1.0",
    "ts-jest": "^26.4.4",
    "ts-loader": "^8.0.14",
    "ts-node": "^8.1.1",
    "tsconfig-paths": "^3.9.0",
    "webpack": "^5.17.0",
    "webpack-cli": "^4.4.0",
    "webpack-node-externals": "^2.5.2"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

@nazarhussain
Copy link
Contributor

Hey @crazyoptimist. Thanks for reaching out to us. I checked the logs you shared.

It's been initiated from the package @0xproject/types@0.1.9 which is dependent on web3@0.20.7.

I am not sure if we can provide any support for such outdated packages. Consider that current version of @0xproject/types is 1.1.4 and for web3 its 1.6.0. I would suggest to use packages in your project which have updated dependencies. For managing outdated deep dependencies in your project, there are some hacks but for that I would suggest to ask JS community.

As the issue is not directly related to web3 library, I am afraid we can't provide you any help into it.

If you found any issue building latest version of web3 in typescript, feel free to re-open this issue.

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

No branches or pull requests

2 participants