cramforce / splittable

Module bundler with support for code splitting, ES6 & CommonJS modules.
Apache License 2.0
945 stars 34 forks source link

Doesn't seem to work with import statements in node modules #45

Open philipwalton opened 7 years ago

philipwalton commented 7 years ago

I've been having problems getting a particular build to work, and I've reduced it down to the fact that I'm including a module from npm that contains an import statement.

Here's my reduced setup:

In the above setup, the code in both the local module and the node module is identical:

export default {
  foo: 'bar'
};

Splittlable works if my entry file looks like this (referencing the local module):

import a from './a';

console.log(a);

But it doesn't work if my entry file looks like this (referencing the node module):

import a from 'a';

console.log(a);

Here's terminal output:

java -jar /Users/philipwalton/.nvm/versions/node/v6.7.0/lib/node_modules/splittable/third_party/closure-compiler/closure-compiler-1.0-SNAPSHOT.jar --apply_input_source_maps true --compilation_level ADVANCED --create_source_map %outname%.map --externs /Users/philipwalton/.nvm/versions/node/v6.7.0/lib/node_modules/splittable/splittable.extern.js --jscomp_off accessControls --jscomp_off globalThis --jscomp_off misplacedTypeAnnotation --jscomp_off nonStandardJsDocs --jscomp_off suspiciousCode --jscomp_off uselessCode --language_in ES6 --language_out ES5 --module_output_path_prefix out/ --new_type_inf true --parse_inline_source_maps true --process_common_js_modules true --rewrite_polyfills true --source_map_location_mapping splittable-build/transformed/|/ --source_map_location_mapping splittable-build/browser/|/ --source_map_location_mapping |/ --js node_modules/a/package.json --js ../../../.nvm/versions/node/v6.7.0/lib/node_modules/splittable/base.js --js node_modules/a/index.js --js ./splittable-build/transformed/index.js --module index:4 --module_wrapper index:self.global=self;%s
//# sourceMappingURL=%basename%.map
 --js_module_root ./splittable-build/transformed/ --js_module_root ./splittable-build/browser/ --js_module_root ./

WARNING - Failed to load module "a.js"

./splittable-build/transformed/index.js:3:
Originally at:
splittable-build/transformed/index.js:3: ERROR - required "module$a" namespace never provided
import a from 'a';
^

1 error(s), 1 warning(s)
philipwalton commented 7 years ago

I should mention that if I rewrite the modules to use CommonJS syntax, both variations work. For example:

In ./a and ./node_modules/a/index.js:

module.exports = {
  foo: 'bar'
};

In ./index:

const a = require('a');

console.log(a);
cramforce commented 7 years ago

Yeah, this is a known issue (see readme for common js limitations), but it will be fixed once an open PR merges in upstream closure compiler.

Let's keep this open to track.

On Dec 31, 2016 6:34 PM, "Philip Walton" notifications@github.com wrote:

I should mention that if I rewrite the modules to use CommonJS syntax, both variations work. For example:

In ./a and ./node_modules/a/index.js:

module.exports = { foo: 'bar' };

In ./index:

const a = require('a'); console.log(a);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cramforce/splittable/issues/45#issuecomment-269890069, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFeT_UGe8xcgt4DPsUELwPhzbM3XFlTks5rNxC-gaJpZM4LYpok .