I am getting the following error when trying to use the babel module "transform-es2015-modules-systemjs".
This error occurs in the gulp build when executing the function specified below compileJs() to transpile ES6 to ES5.
Error:
System.register(['gulp', 'gulp-util', 'run-sequence', 'require-dir', 'del'], function (_export, _context) {
ReferenceError: System is not defined
This package.json fails with gulp:
"babel": {
"presets": [
"es2015"
],
"plugins": [
"angular2-annotations",
"transform-decorators-legacy",
"transform-class-properties",
"transform-flow-strip-types",
"transform-es2015-modules-systemjs"
]
},
This works with gulp however I want the code to be transpiled to a format that SystemJs recognizes for module loading (I am trying to avoid using webpack and browsify) and the default transpiles to CommonJS which the browsers don't recognise yet:
"babel": {
"presets": [
"es2015"
],
"plugins": [
"angular2-annotations",
"transform-decorators-legacy",
"transform-class-properties",
"transform-flow-strip-types"
]
},
Function in gulp to transpile:
function compileJs() {
let enableJsSourceMaps = argv['enable-js-source-maps'] || process.env['GULP_ENABLE_JS_SOURCE_MAPS'] !== undefined;
return gulp.src([
'src/main/webapp/modules/**/*.js'
])
.pipe(gulpIf(enableJsSourceMaps, sourcemaps.init()))
.pipe(babel())
.pipe(gulpIf(enableJsSourceMaps, sourcemaps.write('.')))
.pipe(gulp.dest('target/gulp/main/modules'));
}
index.html that uses SystemJS:
<script>
System.config({
transpiler: "babel",
babelOptions: {
"optional": [
"runtime"
]
},
packages: {
'modules': {
format: 'register',
defaultExtension: 'js'
},
'vendor': {
defaultExtension: 'js'
}
}
});
System.import('modules/config/bootstrap');
</script>
Can anyone shed any light into why this does not work, what I might be missing?
node_modules/systemjs/dist/system.jsorsystem-csp-production.jswith<script>tag. - Shuhei Kagawa