Replies: 4 comments 3 replies
|
What happens when you just run the file? With no package managers? |
|
I encountered another problem about console.log(process.argv.slice(2));When I execute
Could you please help me take a look? Thanks. @avivkeller |
|
Windows being Windows. NTFS is case-insensitive but case-preserving, so the actual stored path might be The difference you're seeing comes from how npm and pnpm spawn child processes:
Neither is wrong. Both paths point to the same directory. If you need consistent casing, import { realpathSync } from "node:fs";
const canonicalCwd = realpathSync.native(process.cwd());Or for path comparison, just go case-insensitive on Windows: import path from "node:path";
function samePath(a, b) {
return path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase();
}Regarding your follow-up about |
|
Typical causes:
What to use instead when you mean “directory of this package/file”: import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// stable regardless of cwdOr for the package root, walk up to the nearest So: normalize on |

Uh oh!
There was an error while loading. Please reload this page.
I started a terminal locally, as shown below. (Note that the path starts with lowercase.)
I wrote a simple code test as shown below.
When I start the script using

pnpmandnpm, I get two different results. I noticed that when I started it withpnpm, the first line of information printed had an additional capitalized path compared to when I started it withnpm.I tried debugging the code, but I couldn't see the implementation inside
rawMethods.cwd().If you have time, please take a look, thank you. @redyetidev
All reactions