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

Let the developer decide: "import foo from 'foo.js'" means foo.js is a module #20

Closed
backspaces opened this issue Jan 17, 2017 · 5 comments

Comments

@backspaces
Copy link

OK, I know there are huge subtleties, but why not just assume the developer knows best and if an import is used, with a .js extension or some other, then just presume it's an es6 module?

Just treat any file using "import" as a module with the transitive closure of imports derived from the file. "import" means it's a module.

I'm sorry if this is naive, but I really don't want "Determining if source is an ES Module" to spiral down a never ending debate.

@caridy
Copy link
Collaborator

caridy commented Jan 30, 2017

@backspaces BC means that you can write new modules using ESM, with the new syntax, and import from a module that might or might not be ESM :/, import statement is not a good signal for this.

@backspaces
Copy link
Author

Does this mean that only the "main" or "top-level" module, the actual node script, needs to use .esm? I hope?!

That's fine. I just want it to be able to import/export .js files.

@SEAPUNK
Copy link

SEAPUNK commented Jan 30, 2017

No, only ES6 module files need to use .esm (or whatever the extension is, if node.js decides to use a new extension for module files).

@SEAPUNK
Copy link

SEAPUNK commented Jan 30, 2017

Assuming node.js or a script bundler like Webpack

Think of it like this:

foo/
  a.js
  b.js
  c.esm
  d.esm

a.js and b.js don't use any of the ES6 module import/export syntax, but they import c.esm via require('./c'), and it'll work.

Conversely, c.esm and d.esm don't use require() but use the new ES6 module import/export syntax, and they can import a.js or b.js with import whatever from './a', and it'll work as well.

An entry script could be any of those.

@backspaces
Copy link
Author

Thanks!

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