define is not defined when trying to move from fontawesome npm to self hosted

524 views Asked by At

I have a Gatsby project that used the FontAwesome 5 Pro NPM registry, font awesome decided to turn off their pro npm registry and now requires a paid subscription to use this service. I wish to move the icons to instead be hosted locally.

What I have done

  • Moved all the icons and the library (react font awesome) to a folder, namely /src/fontAwesome
  • Fixed all the imports to now point the new folder, this took a good while

I am getting an error stating error 'define' is not defined in the index file for all the font awesome folders I moved from node_modules to my /src

Example

/Users/andreas/Documents/prosjekter/gudc/src/fontAwesome/free-solid-svg-icons/index.js
  3:35  error    'define' is not defined                        no-undef
  3:48  error    'define' is not defined                        no-undef
  5:31  warning  'use strict' is unnecessary inside of modules  strict

✖ 3 problems (2 errors, 1 warning)
  0 errors and 1 warning potentially fixable with the `--fix` option.

error undefined failed

My google fu only turned up that I may need require.js, which I added to the project through yarn but this did not resolve the issue. Any ideas son how I can solve this?

See example of the define that fails in use at https://github.com/FortAwesome/react-fontawesome/blob/11ebdc6c1a24b48369bdfb4d7107eb4e2eff794a/index.js#L3

The same line in my codebase

: typeof define === "function" && define.amd
? define([
    "exports",
    "../fontawesome-svg-core",
    "prop-types",
    "react",
  ], factory)

By setting /* eslint no-undef: "off" */ in the root of one of the offending file I get a different error:

/Users/andreas/Documents/prosjekter/gudc/src/fontAwesome/react-fontawesome/index.js
    4:3   error    Expected an assignment or function call and instead saw an expression           no-unused-expressions
   18:28  error    Unexpected use of 'self'                                                        no-restricted-globals
   26:3   warning  'use strict' is unnecessary inside of modules                                   strict
   36:7   warning  '_typeof' is a function                                                         no-func-assign
   40:7   warning  '_typeof' is a function                                                         no-func-assign
   88:47  warning  Function declared in a loop contains unsafe references to variable(s) 'source'  no-loop-func
   97:41  warning  Function declared in a loop contains unsafe references to variable(s) 'source'  no-loop-func
  233:12  warning  Comparing to itself is potentially pointless                                    no-self-compare
  241:31  warning  Unnecessary escape character: \-                                                no-useless-escape

✖ 9 problems (2 errors, 7 warnings)
  0 errors and 1 warning potentially fixable with the `--fix` option.
1

There are 1 answers

0
Andreas On

I resolved this by moving all the free modules that could be in node_modules back there and adding /* eslint no-undef: */ to the top of the index file in the font awesome pro folders I needed.