Replies: 5 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 |
|
The output from process.cwd() actually seems to be the same in both cases: c:\a. The extra C:\a shown when running pnpm test is not produced by process.cwd(). It is part of pnpm's lifecycle script output. With npm you get something like: npm: While pnpm prints the package directory in its script header: pnpm: So the Node.js process itself is still reporting c:\a in both cases. The difference between C:\a and c:\a is also not significant on Windows because Windows paths are normally case-insensitive. Therefore I don't think this is caused by the implementation of process.cwd() or rawMethods.cwd(). It looks like a formatting difference between npm and pnpm's lifecycle output. If you want to verify it independently of the package manager output, you can run: node -e "console.log(process.cwd())" from the same directory and compare that result. |

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