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

ES6 module with no exports is not found with --js_module_root #2247

Closed
alexeagle opened this issue Jan 18, 2017 · 4 comments
Closed

ES6 module with no exports is not found with --js_module_root #2247

alexeagle opened this issue Jan 18, 2017 · 4 comments
Assignees

Comments

@alexeagle
Copy link
Contributor

Repro:

$ npm install google-closure-compiler@20161201.0.0
$ cat user.js
import 'rxjs/add_first';

$ cat stripme/rxjs/add_first.js
import { Observable } from './Observable';
import { first } from './operator_first';
Observable.prototype.first = (first);

$ cat stripme/rxjs/operator_first.js
export function first() {}

$ cat stripme/rxjs/Observable.js
export class Observable {}

$ java -jar node_modules/google-closure-compiler/compiler.jar user.js stripme/rxjs/*.js --entry_point=user.js --js_module_root=stripme
user.js:1: ERROR - required "module$rxjs$add_first" namespace never provided
import 'rxjs/add_first';
^^^^^^^^^^^^^^^^^^^^^^^^

1 error(s), 0 warning(s)

It could be worked around in these ways:

  1. add a trivial export to stripme/rxjs/add_first:
$ cat >> stripme/rxjs/add_first.js
export var a;

$ java -jar node_modules/google-closure-compiler/compiler.jar user.js stripme/rxjs/*.js --entry_point=user.js --js_module_root=stripme
var module$rxjs$Observable={},Observable$$module$rxjs$Observable=function(){};module$rxjs$Observable.Observable=Observable$$module$rxjs$Observable;var module$rxjs$operator_first={};function first$$module$rxjs$operator_first(){}module$rxjs$operator_first.first=first$$module$rxjs$operator_first;var module$rxjs$add_first={};Observable$$module$rxjs$Observable.prototype.first=module$rxjs$operator_first.first;var a$$module$rxjs$add_first;module$rxjs$add_first.a=a$$module$rxjs$add_first;
  1. move the rxjs directory out of stripme/ and remove the --js_module_root argument.
@MatrixFrog MatrixFrog self-assigned this Jan 19, 2017
@ChadKillingsworth
Copy link
Collaborator

I'm guessing a goog.provide statement is only generated when export is seen. Which is incorrect for ES6 modules.

@gregmagolan
Copy link
Contributor

Update on this.

I tested with the latest closure compiler release (20170910) and the build still fails although the failures are different from the failure with 20161201 as described above. Different failures occur depending on configuration (BROWSER or NODE module resolution and relative and ambiguous import path in user.js). I was able to get a successful build with 20170910 but only with a specific configuration: module resolution NODE, relative import path in user.js and the correct order of --js files in closure.conf.

Using the closure compiler dist I made a few days ago (HEAD on 20170919 + patches) the build is successful with module resolution NODE. It worked with both a relative and ambiguous import path in user.js and the order of --js files in closure.conf didn't matter.

Code is here: https://github.com/gregmagolan/closure-test-2247. Test results are described in the README.

@alexeagle
Copy link
Contributor Author

Chad, can you give some update on why this is closed? Do you think the issue is resolved?

@ChadKillingsworth
Copy link
Collaborator

It should have been fixed by #2641 which has now landed (but not yet been released).

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