I have coded ES6 modules as per 2ality's final syntax example, without a .js suffix.
I have as well organised the modules into a vendor/project directory hierarchy and module naming scheme as System.register() module format effectively places registered modules into the same namespace.
The problem is as follows, if I quote 2ality's example:
//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
//------ main.js ------
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
The above works fine directly in the browser, e.g., with traceur and es6-module-loader (see example-es6-modules.html). When the import declaration is encountered a .js suffix seems to be automatically appended to the filename, and lib.js is loaded. As long as System.paths is configured to point to the top of the vendor/project directory then ES6 modules can be executed directly in the browser.
The above also works fine when bundling into a single System.register() module format file with SystemJS builder (see example-system-register.html). As long as baseURL is set to the top of the vendor/project hierarchy (see builder.js) when generating the modules then modules are named with a vendor/project prefix.
The problem is when I attempt to generate CommonJS modules for input to browserify, when carrying out the transform both traceur and es6ify do not append a .js suffix to file names in an import declaration, resulting in errors along the following lines:
$ cd src/es6
$ traceur --out ./out.js --modules commonjs gso/eonjs/EonJS.js
Error: File not found '/home/ ... /src/es6/gso/eonjs/MomentRecurRule'
The above error is because traceur has not added a .js suffix to the 'gso/eonjs/MomentRecurRule' import declaration. Otherwise the file would be found.
If ES6 modules are transcompiled to individual CommonJS modules browserify reports the equivalent error, cannot find the file to import - browserify does not similarly automatically add a .js suffix to the import filename either.
The problem then is, ES6 modules execute in a browser without a problem, load as bundled System.register() modules also, but how to transform to a browser executable?