Loophole: problems with basic usage


I’m not an expert so I’ll try to be as clear as possible:

I am trying loophole to fix an‘unsafe-eval’ error on my electron app.

So I install loophole via npm and then add this line to the top of my js sketch (as it says to do in the readme):
{allowUnsafeEval} = require 'loophole'

But this syntax doesn’t look correct to me and yes, indeed it does not compile:
Uncaught SyntaxError: Unexpected token =

So I modify so that it looks like the correct syntax for importing npm modules:
var {allowUnsafeEval} = require ('loophole')

And as expected, now it compiles. (why does the readme have instructions that do not compile?)

Moving on…

So now I add my problematic library using the weird pointer symbol:
var createGeometry = allowUnsafeEval -> require('three-bmfont-text')

And no, the weird pointer symbol does not compile:
Uncaught SyntaxError: Unexpected token >

So clearly I’m missing something obvious here. How do I correctly use loophole to fix my problematic library?

Much thanks in advance


Are you using JavaScript or CoffeeScript? Because thin arrow functions are CS only.

Ah, that’s not a pointer symbol. We don’t think about pointers here in JS, you always use .. But I don’t think it’s pointers here at all.

Yep, that readme is written in CoffeeScript


Ah thanks. I overlooked the coffeescript tag. My electron app is javascript - can I not use loophole for javascript? I just want to solve the unsafe-eval error I am getting, as explained here.


CoffeeScript is just a different syntax. Use normal JS function syntax and it will be fine.


Thanks @Aerijo
Can anyone tell me the proper javascript syntax for enabling loophole on a specific library? Something like this:
var createGeometry = allowUnsafeEval -> require('three-bmfont-text')


You can use a decaffeinator to convert CS to JS. In this case, it shows var createGeometry = allowUnsafeEval -> require('three-bmfont-text') is equivalent to

const createGeometry = allowUnsafeEval(() => require('three-bmfont-text'));

Whether this is actually what you want, I don’t know.


big thanks @Aerijo for the decaffeinator tip. I was able to get it all working finally.