Created
November 13, 2014 20:33
-
-
Save OliverJAsh/4f8b74153a2f7fdb9f70 to your computer and use it in GitHub Desktop.
sandboxed-module error with transitive ES6 deps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default 'bar'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = 'bar'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Does work: | |
// import bar from './bar'; | |
// Doesn't work: | |
import bar from './bar-es6'; | |
console.log('foo: bar:', bar); | |
export default 'foo'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var traceurAPI = require('traceur/src/node/api.js'); | |
var SandboxedModule = require('sandboxed-module'); | |
var assign = require('lodash-node/modern/objects/assign'); | |
var es6 = function (source) { | |
var compiler = new traceurAPI.NodeCompiler({ modules: 'commonjs' }); | |
return compiler.compile(source); | |
}; | |
// ES6 modules translate to a CJS module with a default property | |
var sandboxEs6Require = function (moduleId, options) { | |
var defaultOptions = { sourceTransformers: { es6: es6 } }; | |
return SandboxedModule.require(moduleId, assign({}, defaultOptions, options)).default; | |
}; | |
var foo = sandboxEs6Require('./foo', { requires: { http: 'mocked http' } }); | |
console.log('main: foo:', foo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sandbox-test", | |
"version": "0.0.0", | |
"dependencies": { | |
"lodash-node": "^2.4.1", | |
"sandboxed-module": "^1.0.2" | |
}, | |
"devDependencies": { | |
"traceur": "0.0.72" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment