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 lookup in ES6. #88

Open
franza opened this issue Jul 22, 2015 · 6 comments
Open

Module lookup in ES6. #88

franza opened this issue Jul 22, 2015 · 6 comments

Comments

@franza
Copy link

franza commented Jul 22, 2015

I'm trying to understand the way modules are loaded in ES6. I was googling this question for like half of hour but never found the exact definition. See the example:

import * as smth from 'dir1/dir2/dir3/file'

You can see that it's different from relative path like ./dir1/dir2/dir3/file. I was messing with this in TypeScript + NodeJS and it's lookup strategy is different from the one I used to work with in NodeJS. What I found is that

  1. it will lookup for dir1 which is defined ABOVE the current file.
  2. If it finds dir1 it tries to find dir2/dir3/file there.
  3. if it fails it continues step 1-2 again and so on.

Is my assumption correct?

@getify
Copy link
Contributor

getify commented Jul 22, 2015

ES6 doesn't specify anything about the meaning of the contents of the module specifier (the string at the end of import statements). From ES6's perspective, it's an opaque value that just represents the module's location in an abstract way.

The hosting environment (browser, node, etc) has to provide a module loader that interprets the contents of the module specifier in a way that makes sense for that env. In node, I imagine the paths will be local file system paths (and behave accordingly), while in the browser, the paths will likely have to be interpreted as remote URLs (and behave accordingly).

The differences you observe may just be an artifact of the reality that module loaders are still un/under specified, so it's all still being sorted out. In any case, it's not an ES6 issue but a web platform issue.

@mrdulin
Copy link

mrdulin commented Jul 11, 2016

Save Questions. What's the ES6 module lookup rules? How does it work?
ex.

import React from 'react';

How does es6 know where is the react.
If I define a module named 'react' too, which one es6 import ?

@hlomzik
Copy link

hlomzik commented Jul 12, 2016

@mrdulin Again, this is not a part of ES6 standard. Path/module resolving should be made by current environment and could differ from one to another.

@mrdulin
Copy link

mrdulin commented Jul 13, 2016

@hlomzik
yeah. Here is my understand:
Because of compiler, like babel, compile es6 import to AMDandcommonJS. so, the path/module resolving rule is theamdandcommonjs` path/module resolving rule?
My English is not good.Sorry for that! Do you understand me ?

@getify
Copy link
Contributor

getify commented Jul 13, 2016

This is not a general support forum. ES6 doesn't specify how the modules are loaded. This repo has nothing to add to your questions. Perhaps try other support forums?

@mrdulin
Copy link

mrdulin commented Jul 13, 2016

@getify OK, I know it. Anyway, Thank you!

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

4 participants