Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Changing all directory import statements to explicitly import index.js #1991

Closed
jpray opened this issue Jan 18, 2018 · 4 comments
Closed

Changing all directory import statements to explicitly import index.js #1991

jpray opened this issue Jan 18, 2018 · 4 comments

Comments

@jpray
Copy link

jpray commented Jan 18, 2018

Hi, I love this project! Would you all consider accepting a PR that changed all directory import statements from import './foo' to import './foo/index.js'? I know node and webpack support the current style but other module loaders like systemjs don't. Thanks for considering this.

@jpray jpray changed the title Changing all relevant import statements to explicitly import index.js Changing all directory import statements to explicitly import index.js Jan 18, 2018
@bonniezhou
Copy link
Contributor

MDC Web only intends to support the formats listed in importing-js.md.
However we encourage you to ask SystemJS to add support for the import './foo' syntax!

@jpray
Copy link
Author

jpray commented Jan 23, 2018

Bummer, I mean, the syntax is still ES2015. The issue is just that having /index.js be implicit isn't part of any standard loader spec that I know of. So a module loader that sticks strictly to a standard like whatwg loader can't support this... and this makes sense because it would be bad for a browser to make multiple calls to the server seeing if foo.js or foo/index.js existed.

It wouldn't be a breaking change. I'd include tests in the PR. :)

@bonniezhou
Copy link
Contributor

Ok...you've convinced us. :) However we still think that the import {...} from 'path/to/index' (without the .js extension) makes most sense, as per http://2ality.com/2014/09/es6-modules-final.html. Adding @kfranqueiro and @acdvorak to this thread in case they want to speak more on it.

Feel free to submit a pull request that:

  • changes all directory imports from import './foo' to import './foo/index'

@jpray
Copy link
Author

jpray commented Jan 26, 2018

Sweet! I'm fine with omitting the '.js' part. I've submitted #2111 for this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants