Skip to main content
shijia.me
Active Member
Jul 14, 2022 12:35 PM UTC
Question

Why Function("return this")() is undefined?

Bug here

if code.js of figma plugin includes Function(return this)(), its value is undefined?

It seems like a bug ONLY since 2022.7.14 🤔

this is my code (removed extraneous code)

  let freeSelf = typeof self === 'object' && self && self.Object === Object && self;
  let root = freeGlobal_default || freeSelf || Function('return this')();

  console.log('Function("return this")()', Function('return this')(), Function); // console here

  let root_default = root;
  let Symbol2 = root_default.Symbol; // oops, bug here

Reproducible code

Add these two lines of code to the webpack-react plugin demo to reproduce.

This topic has been closed for replies.

4 replies

shijia.me
shijia.meAuthor
Active Member
Jul 15, 2022 3:28 AM UTC

Solve this problem by removing developer VM option.

Irvin_Zhan2
Jan 31, 2023 12:53 AM UTC

Is there a better workaround for this? I’d like to use developer VM but cannot due to this bug. Some packages like lodash need global or this to be defined

Semi_Design_UED-MED
Jan 31, 2023 3:19 AM UTC

Sorry Irvin, I do not have a better solution for it.

cihad
New Participant
Feb 25, 2024 5:27 AM UTC

Try: const root = eval('this');