Skip to content

Instantly share code, notes, and snippets.

@barockok barockok/bar-es6.js forked from OliverJAsh/bar-es6.js
Last active Dec 3, 2015

Embed
What would you like to do?
sandboxed-module error with transitive ES6 deps ( solve with babel )
export default 'bar';
module.exports = 'bar';
// Does work:
// import bar from './bar';
// Doesn't work:
import bar from './bar-es6';
console.log('foo: bar:', bar);
export default 'foo';
var babel = require('babel');
var SandboxedModule = require('sandboxed-module');
var assign = require('lodash-node/modern/objects/assign');
var es6 = function (source) {
return babel
.transform(source, {
modules: 'commonStrict'
}).code
};
var sandboxEs6Require = function (moduleId, options) {
var defaultOptions = { sourceTransformers: { es6 } };
return SandboxedModule.require(moduleId, assign({}, defaultOptions, options)).default;
};
var foo = sandboxEs6Require('./foo', { requires: { http: 'mocked http' } });
console.log('main: foo:', foo);
{
"name": "sandbox-test",
"version": "0.0.0",
"dependencies": {
"lodash-node": "^2.4.1",
"sandboxed-module": "^1.0.2"
},
"devDependencies": {
"babel": "5.8.23"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.