Skip to content

Error [ERR_INTERNAL_ASSERTION]: Code: ERR_MODULE_NOT_FOUND; The provided arguments length (2) does not match the required ones (3). #51477

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

Closed
doug-wade opened this issue Jan 15, 2024 · 11 comments

Comments

@doug-wade
Copy link
Contributor

Version

v18.19.0

Platform

Darwin dougs-air.lan 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

  1. Check out the following branch: https://github.com./doug-wade/odyssey-quests/tree/nodejs-bug-report
  2. In a sibling directory, check out this branch as well: https://github.com./doug-wade/tybalt/tree/nodejs-bug-report
  3. build tybalt (yarn install && yarn build)
  4. run yarn link ../tybalt --all from odyssey-quests to link it to this commit: doug-wade/tybalt@5a973a0
  5. Run yarn test in odyssey-quests

How often does it reproduce? Is there a required condition?

It reproduces every time in this current state. I have not done much research into this bug, as the stack contains the message "Please open an issue with this stack trace at https://github.com./nodejs/node/issues", so I'm doing that.

What is the expected behavior? Why is that the expected behavior?

The expected behavior is for the unit tests to run (or, at least, for jest to be invoked).

What do you see instead?

Error [ERR_INTERNAL_ASSERTION]: Code: ERR_MODULE_NOT_FOUND; The provided arguments length (2) does not match the required ones (3).
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com./nodejs/node/issues

    at new NodeError (node:internal/errors:405:5)
    at assert (node:internal/assert:14:11)
    at getMessage (node:internal/errors:451:5)
    at new NodeError (node:internal/errors:379:21)
    at legacyMainResolve (node:internal/modules/esm/resolve:218:9)
    at packageResolve (node:internal/modules/esm/resolve:903:14)
    at moduleResolve (node:internal/modules/esm/resolve:973:20)
    at defaultResolve (node:internal/modules/esm/resolve:1193:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)

Additional information

node 21 gives the following error instead

Error: Cannot find package '/Users/doug/code/tybalt/packages/cli/node_modules/find-up/package.json' imported from /Users/doug/code/tybalt/packages/cli/config/jest.config.js
Did you mean to import "find-up/index.js"?
    at legacyMainResolve (node:internal/modules/esm/resolve:213:26)
    at packageResolve (node:internal/modules/esm/resolve:831:14)
    at moduleResolve (node:internal/modules/esm/resolve:901:20)
    at defaultResolve (node:internal/modules/esm/resolve:1131:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36)

So maybe there's a bug fix that needs to be backported from the active branch to the LTS branch with better error messaging? I wouldn't be surprised if I'm doing something very wrong, since I'm trying to weasel my way around the node_modules directory in a way that supports both monorepos and single packages, and that we're hitting edge cases that just need the new error messaging applied.

@aduh95
Copy link
Contributor

aduh95 commented Jan 16, 2024

Thanks for sending this! Given that the 18.x is in maintenance mode, and the bug is not critical, it's not likely that the fix will be backported. It should be backported to 20.x though (if it's not already, probably on the next release).

Looking at the error message from 21.x, IIUC you are using Jest, which tries to load find-up/package.json. If that find-up is the one one npm, we can see that https://github.com./sindresorhus/find-up/blob/main/package.json defines a "exports" field which does not expose package.json – meaning the package forbids the access to the package.json. (Arguably the error message on 21.x could also be improved.) You can either configure Jest to not try to import that package.json, patch find-up to add "./package.json": "./package.json" in the exports, or move away from Jest and/or find-up.

@doug-wade
Copy link
Contributor Author

No worries @aduh95 ! I figured it was kind of a long-shot, and probably wouldn't have even filed it if the stack didn't tell me too lol. I'll look for a way to fix this in userspace -- should we close the issue, or do we want to keep it around in case someone feels ambitious?

@aduh95
Copy link
Contributor

aduh95 commented Jan 16, 2024

Let's close it for now, as it has already been fixed on more recent versions. We can re-open if more folks encounter it.

@aduh95 aduh95 closed this as completed Jan 16, 2024
@franzos
Copy link

franzos commented Feb 11, 2024

Seeing something similar for nuxt@2 in a node:18 docker image:

api | [0]  FATAL  Code: ERR_MODULE_NOT_FOUND; The provided arguments length (2) does not match the required ones (3).
api | [0] This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
api | [0] Please open an issue with this stack trace at https://github.com./nodejs/node/issues
api | [0]
api | [0]
api | [0]   This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
api | [0]   Please open an issue with this stack trace at https://github.com./nodejs/node/issues
api | [0]
api | [0]   at new NodeError (node:internal/errors:405:5)
api | [0]   at assert (node:internal/assert:14:11)
api | [0]   at getMessage (node:internal/errors:451:5)
api | [0]   at new NodeError (node:internal/errors:379:21)
api | [0]   at legacyMainResolve (node:internal/modules/esm/resolve:218:9)
api | [0]   at packageResolve (node:internal/modules/esm/resolve:903:14)
api | [0]   at moduleResolve (node:internal/modules/esm/resolve:973:20)
api | [0]   at defaultResolve (node:internal/modules/esm/resolve:1193:11)
api | [0]   at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
api | [0]   at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)

EDIT: My bad. Further digging revealed an old dependency; Not sure why this didn't show up till today, but it's fixed.

@ankurparihar
Copy link

HI @aduh95 , when I add package.json in my package as you suggested, i get this error when importing

Error [ERR_INVALID_PACKAGE_CONFIG]: Invalid package config /Users/ankur.parihar/workspace/node_modules/<private-package>/package.json while importing file:///Users/ankur.parihar/server/index.mjs. "exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.

@yujingwyh
Copy link

[ERR_INTERNAL_ASSERTION]: Code: ERR_MODULE_NOT_FOUND; The provided arguments length (2) does not match the required ones (3).

@aduh95
Copy link
Contributor

aduh95 commented Nov 14, 2024

Please update your Node.js version, it has been fixed on all supported Node.js release lines.

@ankurparihar
Copy link

thanks, i resolved it ultimately by await import for my use case

@belav
Copy link

belav commented Dec 5, 2024

I ran into this error on a project that uses vite and is stuck on node18 for the moment.

The fix for me was to wipe out my node_modules, rerun npm install, and then I got the actual error about a bad import in one of my files.

@aduh95
Copy link
Contributor

aduh95 commented Dec 5, 2024

Latest Node.js 18.x should not be affected, I'd recommend updating to that

@belav
Copy link

belav commented Dec 6, 2024

Latest Node.js 18.x should not be affected, I'd recommend updating to that

thanks! I was behind by a couple. Hopefully that will keep it from showing up again.

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

6 participants