exports is undefined?
bluesheeva opened this issue · 2 comments
Hi
I tried to use estraverse as external javascript library for a website that I develop. Whenever I call estraverse (estraverse.traverse), it gaves me an error: 'exports' is undefined. Can someone help with this?
Here are my code:
<script type="text/javascript" src="plugins/esprima.js"></script> <script type="text/javascript" src="plugins/estraverse.js"></script>var ast;
ast = esprima.parse('var answer = 42;var answer2 = 45;function f(){var answer3;}');
ast = JSON.stringify(ast);
var test;
estraverse.traverse(ast, {
enter: function (node, parent) {
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')
return estraverse.VisitorOption.Skip;
},
leave: function (node, parent) {
if (node.type == 'VariableDeclarator')
test += node.id.name;
}
});
I met the same problem yesterday and found that current estraverse codebase is not designed for web browsers. This is not a problem when we use browserify or webpack.
So I built estraverse by myself.
browserify --standalone estraverse node_modules/estraverse/estraverse.js > build/estraverse.browser.js
<script type="text/javascript" src="./path/to/build/estraverse.browser.js"></script>
works as expected.
Hi twada. It works!! thanks for the solution.