3 ms·
I'm not strongly opinionated or informed about this, so why does Node need file extensions when Other languages don't? Is it because of non-JS imports? I know
by jagthebeetle 8y ago
I'm not strongly opinionated or informed about this, so why does Node need file extensions when Other languages don't?
Is it because of non-JS imports? I know that when Ryan dahl announced Deno, he mentioned it as an obviously good change, but, I'm not sure what the problems with extension-less imports are.
(Edit for context: at work, we either use Closure or put everything under a global root, and only import JS, so maybe I've been shielded from the state of the world.)
- snek 8y ago> why does Node need file extensions when Other languages don't? Node allows you to require things that aren't commonjs javascript. (json, native extensions, etc). > when Ryan dahl announced Deno, he mentioned [removing extensionless resolution] as an obviously good change I think a lot of people disagree with ryan dahl in this case (I certainly do). The ability to have a dependency expose an interface without knowing what type of thing that dependency is is very powerful, and i think it is one of the reasons people like require so much.
- ng12 8y ago> The ability to have a dependency expose an interface without knowing what type of thing that dependency is is very powerful Is it? I honestly can't say I've actually used that feature -- although I can say I have gotten burned by it by accidentally importing the wrong thing.
- austincheney 8y agoJavaScript is environment agnostic, such that JavaScript doesn't know what a directory is. Many other languages have a standard library that define these things, but JavaScript does not deliberately to avoid presumptions upon specific environmental constraints that apply in some conditions but not others. A directory is a convention of a file system. When executing in a web browser there is no file system. If they wish to achieve convention and function compatibility with code that works in the browser certain constraints are necessary to prevent assumptions that work in one place and not another. Also, consider the work that happens when resolving files from a directory: 1. You have to determine if the thing is a directory or a file. 2. Get list of files in directory. 3. Read each file 4. Determine if that file is a ESM. 5. Load modules only if the file is ESM. These steps would not work in a browser.