We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There's a weird behaviour where you execute node . within a directory <dir>, and ../<dir>.js will be required before any other file.
node .
<dir>
../<dir>.js
This behaviour doesn't happen for "require"
/app.js
console.log('app');
/app/index.js
console.log('index');
Make sure your CWD is /app and then run node . You will see app printed out.
/app
app
Every time
I'd expect index to be printed out. I'd never expect, in any case, for app to be printed.
index
The order i'd expect (if i have this correct) would be "main" from package.json if it exists, then index.js.
With the current file set-up, and a "main" in package.json pointing to a different file, this is still ignored.
The text was updated successfully, but these errors were encountered:
example code
// main.js const path = require('path') const res = path.resolve(__dirname, 'foo') console.log(res) require(res)
// foo.js console.log('foo.js')
// foo/index.js console.log('foo/index.js')
and files map is
- foo - index.js - foo.js - main.js
run node main.js you can see the issue
node main.js
C:\Users\Himself65\Desktop\github\test>node main.js C:\Users\Himself65\Desktop\github\test\foo foo.js
Sorry, something went wrong.
we use path.resolve to get the main file, but we don't check any else.
path.resolve
maybe we can check files conflict at there
related code:
node/lib/internal/modules/run_main.js
Lines 12 to 14 in 3d894d0
Related to #24210?
@richardlau yup looks like the same issue
/.
/..
Successfully merging a pull request may close this issue.
What steps will reproduce the bug?
There's a weird behaviour where you execute
node .
within a directory<dir>
, and../<dir>.js
will be required before any other file.This behaviour doesn't happen for "require"
/app.js
/app/index.js
Make sure your CWD is
/app
and then runnode .
You will see
app
printed out.How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior?
I'd expect
index
to be printed out. I'd never expect, in any case, forapp
to be printed.The order i'd expect (if i have this correct) would be "main" from package.json if it exists, then index.js.
With the current file set-up, and a "main" in package.json pointing to a different file, this is still ignored.
What do you see instead?
app
Additional information
The text was updated successfully, but these errors were encountered: