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

Strange resolving order using "node ." to start an app #32008

Open
alasdairhurst opened this issue Feb 28, 2020 · 4 comments · May be fixed by #52532
Open

Strange resolving order using "node ." to start an app #32008

alasdairhurst opened this issue Feb 28, 2020 · 4 comments · May be fixed by #52532
Labels
module Issues and PRs related to the module subsystem.

Comments

@alasdairhurst
Copy link

alasdairhurst commented Feb 28, 2020

  • Version: v12.13.0
  • Platform: Windows 10 64 bit
  • Subsystem:

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

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.

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, for app 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

@BridgeAR BridgeAR added the module Issues and PRs related to the module subsystem. label Feb 28, 2020
@himself65
Copy link
Member

himself65 commented Feb 28, 2020

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

C:\Users\Himself65\Desktop\github\test>node main.js
C:\Users\Himself65\Desktop\github\test\foo
foo.js

@himself65
Copy link
Member

we use path.resolve to get the main file, but we don't check any else.

maybe we can check files conflict at there

related code:

let mainPath = Module._findPath(path.resolve(main), null, true);
if (!mainPath)
return;

@richardlau
Copy link
Member

Related to #24210?

@alasdairhurst
Copy link
Author

@richardlau yup looks like the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants