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

@adraffy/ens-normalize resolution error #3848

Closed
JackEdgar opened this issue Mar 1, 2023 · 39 comments
Closed

@adraffy/ens-normalize resolution error #3848

JackEdgar opened this issue Mar 1, 2023 · 39 comments
Assignees
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@JackEdgar
Copy link

JackEdgar commented Mar 1, 2023

Ethers Version

6.0.8

Search Terms

No response

Describe the Problem

Just installed ethers, and can see @adraffy/ens-normalize@1.9.0 is installed via npm list, but it won't resolve in the ethers lib:

Failed to compile.

./node_modules/ethers/lib.esm/hash/namehash.js
Module not found: Can't resolve '@adraffy/ens-normalize' in '/Users/..../node_modules/ethers/lib.esm/hash'

Not sure why this would be happening? Can't use ethers while it has this resolution issue.

Code Snippet

No response

Contract ABI

No response

Errors

Failed to compile.

./node_modules/ethers/lib.esm/hash/namehash.js
Module not found: Can't resolve '@adraffy/ens-normalize' in '/Users/..../node_modules/ethers/lib.esm/hash'

Environment

node.js (v12 or newer), React

Environment (Other)

No response

@JackEdgar JackEdgar added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Mar 1, 2023
@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

Could it be related to RN? Are you using import (as opposed to require)?

@JackEdgar
Copy link
Author

Could it be related to RN? Are you using import (as opposed to require)?

Ethers lib uses:

import { ens_normalize } from "@adraffy/ens-normalize";

I'm importing it via require myself:

const { ethers } = require("ethers");

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

That is probably the problem. If you are using require, it should be using the lib.commonjs, no the lib.esm folder. The ethers lib.commonjs uses require instead of import.

My guess is there is something wrong with the bundler settings? It should be picking up the commonjs folder. What options does RN give for the bundler? Is there a way to tell it to use the exports? Or at least tell it to use the main field?

@JackEdgar
Copy link
Author

That is probably the problem. If you are using require, it should be using the lib.commonjs, no the lib.esm folder. The ethers lib.commonjs uses require instead of import.

My guess is there is something wrong with the bundler settings? It should be picking up the commonjs folder. What options does RN give for the bundler? Is there a way to tell it to use the exports? Or at least tell it to use the main field?

Sorry I'm not actually using RN. Just Node/React. Using:

import { ethers } from "ethers";

results in the same issue.

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

What happens if you try to import @adraffy/ens-normalize directly from your own app?

@JackEdgar
Copy link
Author

Tried commenting out the following line from namehash.js:

import { ens_normalize } from "@adraffy/ens-normalize";

and including it in my own codebase. Not sure if the new import is working as I am now seeing the following error from abi-coder.js which is also using ESM:

./node_modules/ethers/lib.esm/abi/abi-coder.js 108:2
Module parse failed: Unexpected character '#' (108:2)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|   */
| export class AbiCoder {
>   #getCoder(param) {
|     if (param.isArray()) {
|       return new ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name);

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

Oh! What version of node are you using? If it doesn’t support private members (properties that begin with a #), you may be using a version that’s too old. You should be using st least version 16 of node.

@JackEdgar
Copy link
Author

Oh! What version of node are you using? If it doesn’t support private members (properties that begin with a #), you may be using a version that’s too old. You should be using st least version 16 of node.

node -v
v18.14.0

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

That’s weird. It certainly shouldn’t be complaining about private members then.

Actually, looking at your error, it is using Babel; not node. It looks like it is running some preprocessing step. How is the bundler/transpiler triggered?

@JackEdgar
Copy link
Author

I'm just using the following and have installed ethers as an additional dependency as an alternative to web3.js:

https://github.com/alchemyplatform/hello-world-part-four-tutorial/tree/master/starter-files

Error just throws after running npm start.

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

It is definitely doing so strange extra things in the build target, if you look at the package.json.

The error isn’t coming from ethers, it’s coming from Babel during it transpiring the modules. Can you find any docs regarding the build process? It is likely you need to add additional config to the package json (it has a bunch of extra fields in there for handling the custom build logic).

@ricmoo
Copy link
Member

ricmoo commented Mar 1, 2023

@damienmontastier
Copy link

damienmontastier commented Mar 7, 2023

Same error ERROR in ./node_modules/ethers/lib.esm/hash/namehash.js Module not found: Error: Can't resolve '@adraffy/ens-normalize' Failed to compile with 1 errors. This dependency was not found: @adraffy/ens-normalize in ./node_modules/ethers/lib.esm/hash/namehash.js with Nuxt.js 2.15.8 and Node.js 14.21.3. I do just an simple import inside a page like that : import { ethers } from 'ethers'. I didn't have this error before with ethers 5.7.2

@sp1r1don
Copy link

sp1r1don commented Mar 8, 2023

Hello guys! Same here

Error:

Module not found: Can't resolve '@adraffy/ens-normalize'

Packages versions:

node 18.15.0 (tried to downgrade as well)
react 18.2.0
ethers 6.1.0

Import:

import { ethers } from 'ethers'

@ricmoo
Copy link
Member

ricmoo commented Mar 9, 2023

Thanks. I’m still trying to figure out how to reproduce this. Is there a simple webpack config you can provide that results in this error?

@goosewobbler
Copy link

We get this trying to upgrade ethers to v6 in Frame, using Parcel.

@ricmoo
Copy link
Member

ricmoo commented Mar 9, 2023

Random question. After upgrading to ethers v6, did you re-run install?

I'm trying out webpack (which seems the above systems use) and it seems to work. I'm trying everything I can think of to reproduce this... Any help is appreciated.

@ricmoo
Copy link
Member

ricmoo commented Mar 9, 2023

(and can you verify there is a folder node_modules/@adraffy/ens-normalize?)

@sp1r1don
Copy link

sp1r1don commented Mar 9, 2023

Thanks. I’m still trying to figure out how to reproduce this. Is there a simple webpack config you can provide that results in this error?

Just installed react-create-app, then added ethers last version.

I have this package in node_modules @adraffy/ens-normalize 1.8.9

@ricmoo
Copy link
Member

ricmoo commented Mar 9, 2023

Thanks. I’ll try that out.

@start940315
Copy link

Exact same issue here.

@ricmoo
Copy link
Member

ricmoo commented Mar 10, 2023

I definitely need som help reproducing this. I want to help, but I need more than "me too" replies.

Here is what I've done:

  1. npm install create-react-app
  2. npx create-react-app my-react-app
  3. cd my-react-app
  4. npm install ethers
  5. nano src/App.js; added import { ethers } from "ethers" and added { ethers.namehash("ricmoo.eth") } to the output
  6. npm start

To which I get a page with the name hash injected properly.

Please let me know simple and complete reproduction steps. :)

@samuelmonday699

This comment was marked as spam.

@start940315
Copy link

Maybe because we add react-app-rewired?

@ricmoo
Copy link
Member

ricmoo commented Mar 10, 2023

Please keep in mind I have next to zero knowledge of react native, so I need more explanation of things like “react-app-rewired” and how I can exploit that to replicate the above error. :)

@goosewobbler
Copy link

@HELMAB
Copy link

HELMAB commented Mar 13, 2023

I get into the same error, but when I try to downgrade to npm install ethers@5 it works fine for me.

@ricmoo
Copy link
Member

ricmoo commented Mar 13, 2023

Thanks @goosewobbler! I can now reproduce the problem. Trying to figure out the issue now. :)

@ricmoo
Copy link
Member

ricmoo commented Mar 13, 2023

The issues seems to be with how parcel applies browser overrides. I have been debating removing the xnf version of the ens_normalize; it saves a bit on bundle size, but places ENS resolution at the mercy of browser normalize, which has spotty standards-compliance.

So, in v6.2 I will switch to using the standards-compliant normalize included in the @adraffy/ens-normalize module, which should get rid of this error and improve standards-compliance for funky ENS names. :)

@start940315
Copy link

What about this problem? I get stuck by this problem too. It seems like the loader did not transpile ethers file.

Tried commenting out the following line from namehash.js:

import { ens_normalize } from "@adraffy/ens-normalize";

and including it in my own codebase. Not sure if the new import is working as I am now seeing the following error from abi-coder.js which is also using ESM:

./node_modules/ethers/lib.esm/abi/abi-coder.js 108:2
Module parse failed: Unexpected character '#' (108:2)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|   */
| export class AbiCoder {
>   #getCoder(param) {
|     if (param.isArray()) {
|       return new ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name);

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. labels Mar 20, 2023
@ricmoo
Copy link
Member

ricmoo commented Mar 20, 2023

This should be fixed in v6.2.0. Please try it out and let me know. :)

@tmpfs
Copy link

tmpfs commented Mar 21, 2023

Thanks @ricmoo, this fixed the problem for me using both parcel and webpack.

I should probably raise a separate issue but now typescript complains about the #private declaration in Transaction.d.ts (causing a type mismatch):

  ...snip...
  node_modules/ethers/types/transaction/transaction.d.ts:77:5
    77     #private;
           ~~~~~~~~
    '#private' is declared here.

Any pointers on how to coax typescript into respecting that declaration?

@ricmoo
Copy link
Member

ricmoo commented Mar 21, 2023

@tmpfs What is causing the type issue? That definitely shouldn’t cause any type issues as long as you aren’t including different minor versions within the same project…

@ricmoo ricmoo closed this as completed Mar 21, 2023
@Kayaba-Attribution
Copy link

I had this issue while using jest.

Solved it by adding the following:

jest.config.js:

  testEnvironment: "node",
  transformIgnorePatterns: [
    'node_modules/(?!(@adraffy/ens-normalize)/)',
  ],
  transform: {
    '^.+\\.(js|ts)$': '<rootDir>/jest-transformer.js',
  } 

jest-transformer.js:

const { createTransformer } = require('babel-jest');

const babelOptions = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
    '@babel/preset-typescript',
  ],
};

module.exports = createTransformer(babelOptions);

@eyooooo
Copy link

eyooooo commented May 29, 2023

sorry to reopen old thread, i just installed ethers and have the associated error.

im on node v14.20.1 if that matters :)

i just did a fresh npm init and npm i ethers and got the error trying to run a small script.

@omnus
Copy link

omnus commented May 30, 2023

I'm finding this issue too, I think it has something to do with how npm is handling the nested dependency.

If I install @adraffy/ens-normalize directly I get the dist folder. If I navigate to node_modules/ethers/node_modules/@adraffy/ens-normalise there is no dist folder.

If I copy the dist folder from node_modules/@adraffy/ens-normalise to the path listed above I get past this issue (and on to the next issue in my migration from v5 lol).

So, how do we force the @adraffy/ens-normalise within the ethers directory to get a dist folder and contents?

@omnus
Copy link

omnus commented May 30, 2023

Just noticed this issue is closed, will create a new one...

@iamveervikram
Copy link

I get into the same error, but when I try to downgrade to npm install ethers@5 it works fine for me.

yah, it works
thnks

@warao-gil
Copy link

it works in v6.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

15 participants