figma-plugin-helpers icon indicating copy to clipboard operation
figma-plugin-helpers copied to clipboard

TypeError: Cannot read property 'Symbol' of undefined

Open Baraksi opened this issue 4 years ago • 18 comments

Hey, I seem to get an error every time I try to use an helper function (specifically loadUniqueFonts or getBoundingRect, didn't try others) and then run the plugin locally on Figma for Windows 10. When I remove all of the usages my plugin runs, adding a call to an helper function prevents the plugin from opening and yields this error on Figma console:

TypeError: Cannot read property 'Symbol' of undefined
    at Object../node_modules/lodash/_Symbol.js (VM1261 PLUGIN_9_SOURCE:18085)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_baseGetTag.js (VM1261 PLUGIN_9_SOURCE:18902)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/isSymbol.js (VM1261 PLUGIN_9_SOURCE:23264)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_isKey.js (VM1261 PLUGIN_9_SOURCE:21458)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)
    at Object../node_modules/lodash/_castPath.js (VM1261 PLUGIN_9_SOURCE:19909)
    at __webpack_require__ (VM1261 PLUGIN_9_SOURCE:20)

I understand it may seem like a lodash error, but as I mentioned when I remove all of @figma-plugin/helpers usages, there's no error. BTW, running the same code with all the usages on Mac seems to work without having this error.

Worth adding, on version 0.14.3 the same behavior happens, with a different error that is more indicative towards the helpers package. I updated to the latest version before opening the issue to check if it was already fixed.

Let me know if I can provide more details about it. Thanks!

Baraksi avatar Feb 19 '21 19:02 Baraksi

Adding that pressing the code location (VM1261 PLUGIN_9_SOURCE:18085) from the console directs me to this line

image

I researched into it and found this, checked lodash repo and it seems there was a change in the relevant code, so I locally patched package.json of the helpers module to use the latest lodash version, then 'npm install' - unfortunately, the error persists, though not 100% sure if the patch was taken into account.

Baraksi avatar Feb 23 '21 14:02 Baraksi

I'm having the same issue here, @Baraksi could you please provide what exactly the workaround you did was?

danilowoz avatar Apr 07 '21 09:04 danilowoz

@danilowoz Well, after patching the helpers module locally to use lodash latest version didn't work, I ended up copying the helper functions that I needed and uninstalling the helpers module

Baraksi avatar Apr 11 '21 14:04 Baraksi

Thanks for reporting Could you guys attach your package.json? It seems like a conflict thing, not something inside the package

alexandrtovmach avatar Apr 11 '21 16:04 alexandrtovmach

I'll check if bump lodash helps, and if yes will release fixed version soon

alexandrtovmach avatar Apr 11 '21 16:04 alexandrtovmach

v0.15.2 of helpers contain experimental fix for getBoindingRect (basically it shows more information in logs what goes wrong). If it works, please provide the list of helpers with similar issues, I'll try to handle it and make another release

alexandrtovmach avatar Apr 11 '21 21:04 alexandrtovmach

Hey @alexandrtovmach, I'm still getting the same error on the latest version. Here's my package.json, hope it helps:

 "dependencies": {
    "clsx": "^1.1.1",
    "deep-object-diff": "^1.1.0",
    "deepmerge": "^4.2.2",
    "design-system": "0.0.1",
    "figma-messenger": "^1.0.5",
    "humanize-string": "^2.1.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "tailwindcss": "^2.0.3"
  },
  "devDependencies": {
    "@babel/preset-typescript": "^7.13.0",
    "@figma-plugin/helpers": "^0.15.2",
    "@figma/plugin-typings": "^1.19.2",
    "@svgr/webpack": "^5.5.0",
    "@testing-library/react-hooks": "^5.1.0",
    "@types/react": "^17.0.3",
    "@types/react-dom": "^17.0.1",
    "autoprefixer": "^9.8.6",
    "babel-loader": "^8.2.2",
    "css-loader": "^5.1.1",
    "file-loader": "^6.2.0",
    "html-webpack-inline-source-plugin": "0.0.10",
    "html-webpack-plugin": "^3.2.0",
    "jest": "^26.6.3",
    "postcss": "^8.2.8",
    "postcss-loader": "^4.2.0",
    "style-loader": "^2.0.0",
    "ts-jest": "^26.5.4",
    "ts-loader": "^8.0.17",
    "tsconfig-paths-webpack-plugin": "^3.5.1",
    "typescript": "^4.2.3",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  }

danilowoz avatar Apr 12 '21 08:04 danilowoz

@danilowoz great, could you also attach a list of helpers do you use? (or better to say "trying to use" 😄 )

alexandrtovmach avatar Apr 12 '21 08:04 alexandrtovmach

Sure, the following ones:

  • figmaRGBToHex
  • hexToFigmaRGB
  • webRGBToFigmaRGB

danilowoz avatar Apr 12 '21 08:04 danilowoz

Hi @alexandrtovmach , same error when using extractLinearGradientParamsFromTransform.

myWsq avatar Jun 01 '21 02:06 myWsq

Hey @alexandrtovmach, I'm trying to use getBoundingRect but the error in OP persists. Are you still actively looking for a fix for this issue?

rpcabrinha avatar Dec 27 '21 15:12 rpcabrinha

could you provide any logs or steps to reproduce please?

alexandrtovmach avatar Dec 27 '21 22:12 alexandrtovmach

We're working on an internal plugin at Intuit and interestingly some people get this error (me) and some don't. Seems like it has something to do with the Figma environment, not the build environment, since the code my coworker built runs fine on her machine, but I still get the error.

Figured it out! Unchecking Use Developer VM fixed the issue, which explains why the published plugin always worked.

image

brettlyne avatar Jan 07 '22 22:01 brettlyne

Just noticed @rpcabrinha got this answer from Vlad Korzo with a webpack fix over at figmaplugins.slack.com:

in development mode you need to add

config.plugins.push(
 new webpack.DefinePlugin({
  global: {}, // Fix missing symbol error when running in developer VM
 }),
);

brettlyne avatar Jan 08 '22 00:01 brettlyne

@alexandrtovmach thanks for replying. In the end I opted for a different way to build my Figma plugin. However, just like @brettlyne mentioned, it seems to be a problem with the Figma environment.

rpcabrinha avatar Jan 17 '22 15:01 rpcabrinha

We're working on an internal plugin at Intuit and interestingly some people get this error (me) and some don't. Seems like it has something to do with the Figma environment, not the build environment, since the code my coworker built runs fine on her machine, but I still get the error.

Figured it out! Unchecking Use Developer VM fixed the issue, which explains why the published plugin always worked.

image

Also just ran into this and toggling the developer VM off worked for me

phoenixbox avatar Dec 04 '22 23:12 phoenixbox

Just noticed @rpcabrinha got this answer from Vlad Korzo with a webpack fix over at figmaplugins.slack.com:

in development mode you need to add

config.plugins.push(
 new webpack.DefinePlugin({
  global: {}, // Fix missing symbol error when running in developer VM
 }),
);

not work

linjinxing avatar Dec 29 '23 23:12 linjinxing

My solution was:

// https://vitejs.dev/config/
export default defineConfig({
  // ...
  build: {
    rollupOptions: {
      // ...
      output: {
        entryFileNames: '[name].js',
        intro: "const window = eval('this'); void window;"
      },
    },
  },
})

intro is important here. void window; is necessary because tree-shaking. I don't need to disable developer VM now.

cihad avatar Feb 25 '24 05:02 cihad