【问题标题】:define is not defined when trying to move from fontawesome npm to self hosted尝试从 fontawesome npm 迁移到自托管时未定义定义
【发布时间】:2021-03-23 16:06:16
【问题描述】:

我有一个使用 FontAwesome 5 Pro NPM 注册表的 Gatsby 项目,font awesome 决定关闭他们的 pro npm 注册表,现在需要付费订阅才能使用此服务。我希望将图标移动到本地托管。

我做了什么

  • 将所有图标和库(react font awesome)移动到一个文件夹,即 /src/fontAwesome
  • 已将所有导入修复为现在指向新文件夹,这需要一段时间

对于我从 node_modules 移动到 /src 的所有字体真棒文件夹,我在索引文件中收到错误声明错误 'define' is not defined

例子

/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

我的 google fu 只发现我可能需要 require.js,我通过 yarn 将其添加到项目中,但这并没有解决问题。有什么想法儿子我该如何解决这个问题?

查看使用失败的定义示例 https://github.com/FortAwesome/react-fontawesome/blob/11ebdc6c1a24b48369bdfb4d7107eb4e2eff794a/index.js#L3

我的代码库中的同一行

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

通过在一个有问题的文件的根目录中设置/* eslint no-undef: "off" */,我得到一个不同的错误:

/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.

【问题讨论】:

    标签: reactjs font-awesome gatsby font-awesome-5


    【解决方案1】:

    我解决了这个问题,方法是将 node_modules 中可能存在的所有免费模块移回那里,并将/* eslint no-undef: */ 添加到我需要的 font awesome pro 文件夹的索引文件顶部。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2019-01-08
      • 2018-11-03
      • 2019-07-26
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 2016-03-16
      相关资源
      最近更新 更多