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

Module resolution should not succeed but does #43342

Closed
amcasey opened this issue Mar 23, 2021 · 5 comments
Closed

Module resolution should not succeed but does #43342

amcasey opened this issue Mar 23, 2021 · 5 comments

Comments

@amcasey
Copy link
Member

amcasey commented Mar 23, 2021

a.ts

export {}

b.ts

import "BAD/../../a";

node_modules/
Present but empty

Expected: import fails to resolve
Actual: import resolves because we look in node_modules/BAD/../../a, which simplifies to a.

The path normalization in question happens here.

@amcasey
Copy link
Member Author

amcasey commented Mar 23, 2021

Maybe we need to normalize the path before checking if it's relative?

@amcasey
Copy link
Member Author

amcasey commented Mar 23, 2021

I suppose there's a tiny chance this is desirable, even if it appears to be happening by accident. @sheetalkamat ?

@amcasey
Copy link
Member Author

amcasey commented Mar 23, 2021

On further reflection, the is-relative-path check probably needs to check path components after the first one.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 23, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.1 milestone Mar 23, 2021
@sheetalkamat
Copy link
Member

sheetalkamat commented Mar 23, 2021

I dont think this is issue with module resolution.. Node works in similar way. If you make those file at runtime as js files and run them it works

c:\temp\test>type a.js
module.exports = { a: 10};
c:\temp\test>type b.js
const r = require("BAD/../../a");
console.log(r);
c:\temp\test>dir node_modules
 Volume in drive C is OSDisk
 Volume Serial Number is F41A-DBC9

 Directory of c:\temp\test\node_modules

03/23/2021  01:40 PM    <DIR>          .
03/23/2021  01:40 PM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  689,911,324,672 bytes free

c:\temp\test>node b.js
{ a: 10 }

@sheetalkamat sheetalkamat removed the Bug A bug in TypeScript label Mar 23, 2021
@sheetalkamat sheetalkamat removed their assignment Mar 23, 2021
@amcasey
Copy link
Member Author

amcasey commented Mar 23, 2021

Well, now I'm sad.

@amcasey amcasey closed this as completed Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants