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

Error: Cannot find module 'is-odd' #4372

Open
vfilatov opened this issue Apr 15, 2024 · 17 comments
Open

Error: Cannot find module 'is-odd' #4372

vfilatov opened this issue Apr 15, 2024 · 17 comments

Comments

@vfilatov
Copy link

vfilatov commented Apr 15, 2024

Version

v20.12.1

Platform

Linux dev 5.10.0-28-amd64 nodejs/node#1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

The original issue sveltejs/kit#11912

git clone https://github.com/gtm-nayan/node-socket-import-error.git
cd node-socket-import-error/
rm package-lock.json pnpm-lock.yaml
pnpm i
node index.mjs

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

No response

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

If package installed with npm i it does not throw the error below

What do you see instead?

node:internal/modules/cjs/loader:1048
  const err = new Error(message);
              ^

Error: Cannot find module 'is-odd'
Require stack:
- /tmp/node-socket-import-error/node_modules/is-even/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/tmp/node-socket-import-error/node_modules/is-even/index.js:10:13)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:165:29) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/tmp/node-socket-import-error/node_modules/is-even/index.js' ]
}

Node.js v20.5.1

Additional information

No response

@vfilatov vfilatov changed the title Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rollup' imported from Error: Cannot find module 'is-odd' Apr 15, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented Apr 15, 2024

Hi! This repo is issues with the NodeJS core, and this looks like an issue with a package installation.

But, to answer your question, modules are usually installed with npm install <module> (or similar, depending on your package manager).
Installed packages typically appear in ./node_modules/<module>, so if that folder doesn't exist, than the package is not installed.

If your experiencing an issue with pnpm, please file an issue in their repository.

Thank you!

@RedYetiDev
Copy link
Member

Thanks!

@VoltrexKeyva, I believe this is a wrong-repo issue. Could you label it when you get a chance? Thank you!

Pinging you as you edited the question (and are a member of the triage team)

@MoLow MoLow transferred this issue from nodejs/node Apr 16, 2024
@vfilatov
Copy link
Author

vfilatov commented May 3, 2024

Hi! This repo is issues with the NodeJS core, and this looks like an issue with a package installation.

But, to answer your question, modules are usually installed with npm install <module> (or similar, depending on your package manager). Installed packages typically appear in ./node_modules/<module>, so if that folder doesn't exist, than the package is not installed.

If your experiencing an issue with pnpm, please file an issue in their repository.

Thank you!

They insist that is a nodejs bug.
pnpm/pnpm#7931 (comment)

@ahaoboy
Copy link

ahaoboy commented May 5, 2024

Both forms of code run fine, so the dependencies are installed correctly

// index.js
// node ./index.js

const isEven = require('is-even')
console.log(isEven(1))
// index.mjs
// node ./index.mjs
import * as isEven from 'is-even'
console.log(isEven.default(1))

Esbuild can also bundle correctly

 esbuild ./index.mjs --bundle --platform=node

@ahaoboy
Copy link

ahaoboy commented May 5, 2024

I found an interesting thing. This line of code will affect the execution results. After commenting it out, it will only report an error the first time it is run. After that, it can run correctly every time. After removing the comment, it will report an error every time it is run.

import fs from 'fs';
import { createServer } from 'net';
const mySocketFile = '/tmp/mysocketfile';

if (fs.statSync(mySocketFile, { throwIfNoEntry: false }))
  fs.unlinkSync(mySocketFile);

// magic line
createServer((socket) => { }).listen(mySocketFile);

setTimeout(async () => {
  const isEven = await import("is-even")
  console.log("isEven: ", isEven.default(1))
});
 node --version
v22.1.0

@ahaoboy
Copy link

ahaoboy commented May 5, 2024

@vfilatov Can you test using node 18? On my machine node18 doesn't have this problem

@RedYetiDev RedYetiDev added question needs more info issues that need more info from the author and removed help wanted labels May 6, 2024
@vfilatov
Copy link
Author

vfilatov commented May 8, 2024

@vfilatov Can you test using node 18? On my machine node18 doesn't have this problem

Yes, this particular example working on node18.
But this example is a simplified code from the original issue, which NOT working on node18 either.

sveltejs/kit#11912

@vfilatov
Copy link
Author

vfilatov commented May 8, 2024

I found an interesting thing. This line of code will affect the execution results. After commenting it out, it will only report an error the first time it is run. After that, it can run correctly every time. After removing the comment, it will report an error every time it is run.

import fs from 'fs';
import { createServer } from 'net';
const mySocketFile = '/tmp/mysocketfile';

if (fs.statSync(mySocketFile, { throwIfNoEntry: false }))
  fs.unlinkSync(mySocketFile);

// magic line
createServer((socket) => { }).listen(mySocketFile);

setTimeout(async () => {
  const isEven = await import("is-even")
  console.log("isEven: ", isEven.default(1))
});
 node --version
v22.1.0

Yes, that is the point!
Initially I though the problem is on the SvelteKit side, but this simplified code excludes all SvelteKit relations.
It is either pnpm or node.
As you found the (simplified) code working under node18 that makes me suspect the code might be on node core...

@RedYetiDev
Copy link
Member

Hi! If you delete the package-lock and pnpm-lock files and run npm i, then test the code in the latest version (v20.1.3 for LTS), will this issue still occur?

@vfilatov
Copy link
Author

vfilatov commented May 8, 2024

Hi! If you delete the package-lock and pnpm-lock files and run npm i, then test the code in the latest version (v20.1.3 for LTS), will this issue still occur?

Yes, it is working when I use npm
I mean there is no issues when using npm

@RedYetiDev
Copy link
Member

So this probably isn't an issue with npm. What happens when you follow the same instructions but use pnpm instead?

@RedYetiDev RedYetiDev removed the needs more info issues that need more info from the author label May 8, 2024
@vfilatov
Copy link
Author

vfilatov commented May 8, 2024

So this probably isn't an issue with npm. What happens when you follow the same instructions but use pnpm instead?

when I use pnpm and node 20, I get the error above.
when I use pnpm and node 18, I do not get the error above.
when I use npm and any node, I do not get the error above.

@RedYetiDev
Copy link
Member

So, despite what the pnpm team may have said, it really doesn't seem like an issue with Node.

@vfilatov
Copy link
Author

vfilatov commented May 8, 2024

So, despite what the pnpm team may have said, it really doesn't seem like an issue with Node.

It might an issue on both sides... As something changed between node18 & node20...
Would be great if somebody could simply debug the code and find that "breaking point".
May guess that bug could be fixed by either team.

@RedYetiDev
Copy link
Member

Well, the change from Node.js v18 to Node.js v20 was breaking, as with major release lines, so breakages are expected, maybe the pnpm team knows?

@ahaoboy
Copy link

ahaoboy commented May 12, 2024

Well, the change from Node.js v18 to Node.js v20 was breaking, as with major release lines, so breakages are expected, maybe the pnpm team knows?

Someone more familiar with both libraries would need to investigate this in depth, and as a short-term solution, maybe try running it with bun for now?

@RedYetiDev
Copy link
Member

Marking as NPM ad this regards it vs pnpm

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

No branches or pull requests

4 participants