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

ESM resolution for the web3-errors package problem. #6359

Closed
EmilIvanichkovv opened this issue Aug 15, 2023 · 15 comments
Closed

ESM resolution for the web3-errors package problem. #6359

EmilIvanichkovv opened this issue Aug 15, 2023 · 15 comments
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@EmilIvanichkovv
Copy link

EmilIvanichkovv commented Aug 15, 2023

Expected behavior

The ESM (ECMAScript Modules) resolution for the web3-errors package should function correctly.

Actual behavior

Currently, the ESM resolution for the web3-errors package is not functioning as expected.

Steps to reproduce the behavior

  1. Install the Package: Execute the command yarn add web3-errors to install the web3-errors package.
  2. Create a Test File: Create a file named test.mjs with the following content:
import * as errors from 'web3-errors'
  1. Run the File: Execute the command node test.mjs.

Logs

node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/web3-errors/lib/esm/error_codes' imported from /node_modules/web3-errors/lib/esm/errors/rpc_error_messages.js
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Environment

Node.js v18.16.0
web3-errors@npm:1.1.0 (via npm:^1.1.0)

Additional Note:

Under the esm folder of the package, specifically in the file node_modules/web3-errors/lib/esm/errors/rpc_error_messages.js, there is a line:
import { ERR_RPC_INTERNAL_ERROR, ERR_RPC_INVALID_INPUT, ERR_RPC_INVALID_JSON, ERR_RPC_INVALID_METHOD, ERR_RPC_INVALID_PARAMS, ERR_RPC_INVALID_REQUEST, ERR_RPC_LIMIT_EXCEEDED, ERR_RPC_MISSING_RESOURCE, ERR_RPC_NOT_SUPPORTED, ERR_RPC_TRANSACTION_REJECTED, ERR_RPC_UNAVAILABLE_RESOURCE, ERR_RPC_UNSUPPORTED_METHOD, JSONRPC_ERR_CHAIN_DISCONNECTED, JSONRPC_ERR_DISCONNECTED, JSONRPC_ERR_REJECTED_REQUEST, JSONRPC_ERR_UNAUTHORIZED, JSONRPC_ERR_UNSUPPORTED_METHOD, } from '../error_codes';
This approach of importing from a relative path (../error_codes) might not be suitable for ESM (ECMAScript Modules). It seems that the import should be from error_codes.js. The potential root of this issue could be related to the packaging process. Yesterday, before Release/4.1.0 of web3 with version 1.0.2 of web3-errors I didn't have this problem

@jdevcs jdevcs added 4.x 4.0 related Bug Addressing a bug labels Aug 15, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Aug 15, 2023

Thanks for creating issue, its fix will be available in next patch soon.

@EmilIvanichkovv
Copy link
Author

By the way, I've noticed a similar issue in web3-validator as well.

@rewiaca
Copy link

rewiaca commented Aug 16, 2023

Ah, have no previous versions, just starting from scratch. How should all these packages be installed, which version and for which package? npm i web3@4.0.1 doesnt make a change

@syamsoul
Copy link

syamsoul commented Aug 17, 2023

By the way, I've noticed a similar issue in web3-validator as well.

ya ... hope can fix this too...

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/myproj/node_modules/web3-validator/lib/esm/formats' imported from /myproj/node_modules/web3-validator/lib/esm/validator.js

as in Node documentation, must provide file extension..

A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes (e.g. './startup/index.js') must also be fully specified.

@VitalyEmelyanov
Copy link

Same problem, the '.js' extension should be strictly specified in these files

ERROR in ./node_modules/web3-errors/lib/esm/errors/rpc_error_messages.js

Module not found: Can't resolve imported dependency "../error_codes"

ERROR in ./node_modules/web3-validator/lib/esm/validator.js

Module not found: Can't resolve imported dependency "./formats"

@sonejjjjj
Copy link

sonejjjjj commented Aug 17, 2023

Same problem with
import { Web3 } from 'web3';

error - Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/web3-errors/lib/esm/error_codes' imported from .../node_modules/web3-errors/lib/esm/errors/rpc_error_messages.js
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:416:11)
    at moduleResolve (node:internal/modules/esm/resolve:932:10)
    at defaultResolve (node:internal/modules/esm/resolve:1044:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  digest: undefined
}

@wongtsejian
Copy link

wongtsejian commented Aug 17, 2023

Same problem as above while using v4.0.3:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/tsejian/orchid-wallet/node_modules/web3-errors/lib/esm/error_codes' imported from /Users/tsejian/orchid-wallet/node_modules/web3-errors/lib/esm/errors/rpc_error_messages.js
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:326:11)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  page: '/'
}

Using an older version of Web3 (4.0.3) also does not work as the dependencies of Web3 v4.0.3 includes web3-validator, web3-errors and their versions were stated as "^1.0.2" which caused the latest buggy version "2.0.0" or "1.1.0" to be pulled instead of the stable "1.0.2".

@EmilIvanichkovv
Copy link
Author

EmilIvanichkovv commented Aug 17, 2023

A possible temporal workaround for me was to specify resolutions in my package.json as I use yarn
Like that:

{
  "resolutions": {
    "web3-core": "4.0.3",
    "web3-errors": "1.0.2",
    "web3-eth": "4.0.3",
    "web3-eth-abi": "4.0.3",
    "web3-eth-accounts": "4.0.3",
    "web3-eth-contract": "4.0.3",
    "web3-eth-ens": "4.0.3",
    "web3-eth-iban": "4.0.3",
    "web3-eth-personal": "4.0.3",
    "web3-net": "4.0.3",
    "web3-providers-http": "4.0.3",
    "web3-providers-ws": "4.0.3",
    "web3-rpc-methods": "1.0.2",
    "web3-types": "1.0.2",
    "web3-utils": "4.0.3",
    "web3-validator": "1.0.2"
  }
}

For npm/pnpm go with dependencies instead of resolutions

@jdevcs jdevcs self-assigned this Aug 17, 2023
@jdevcs jdevcs mentioned this issue Aug 17, 2023
17 tasks
@jdevcs
Copy link
Contributor

jdevcs commented Aug 18, 2023

Fix is published in dev tag on npm: 4.1.1-dev.86f0cdb.0
pls reopen issue if you face same issue.

@jdevcs jdevcs closed this as completed Aug 18, 2023
@EmilIvanichkovv
Copy link
Author

It seems that this has resolved the issue. Thank you!

Could you please provide an estimate for when we can anticipate an official release?

@jdevcs jdevcs mentioned this issue Aug 18, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Aug 18, 2023

@EmilIvanichkovv early next week ( #6367 )

@wongtsejian
Copy link

A possible temporal workaround for me was to specify resolutions in my package.json as I use yarn Like that:

{
  "resolutions": {
    "web3-core": "4.0.3",
    "web3-errors": "1.0.2",
    "web3-eth": "4.0.3",
    "web3-eth-abi": "4.0.3",
    "web3-eth-accounts": "4.0.3",
    "web3-eth-contract": "4.0.3",
    "web3-eth-ens": "4.0.3",
    "web3-eth-iban": "4.0.3",
    "web3-eth-personal": "4.0.3",
    "web3-net": "4.0.3",
    "web3-providers-http": "4.0.3",
    "web3-providers-ws": "4.0.3",
    "web3-rpc-methods": "1.0.2",
    "web3-types": "1.0.2",
    "web3-utils": "4.0.3",
    "web3-validator": "1.0.2"
  }
}

For npm/pnpm go with dependencies instead of resolutions

@EmilIvanichkovv although this didn't worked for me, thanks for the suggestion. The dev release @jdevcs posted works!.

@devarteneur
Copy link

The development release now appears to be functional on Windows and Mac M1s as well. Thank you, @jdevcs, for your contributions. Prior to this, I had observed consistent performance only on Linux machines.

@jdevcs
Copy link
Contributor

jdevcs commented Aug 21, 2023

Patch release is now available :
https://www.npmjs.com/package/web3/v/4.1.1
https://github.com/web3/web3.js/releases/tag/v4.1.1

@jdevcs
Copy link
Contributor

jdevcs commented Aug 21, 2023

Thanks every one for testing dev and all feedback.

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

No branches or pull requests

8 participants