简体   繁体   English

导入 fontawesome 图标时出错

[英]Getting error when importing fontawesome icons

I'm trying to build a simple website using Astro, it runs perfectly fine when using astro dev but I can't build the website using astro build because this happens:我正在尝试使用 Astro 构建一个简单的网站,它在使用astro dev时运行得非常好,但我无法使用astro build构建网站,因为发生了这种情况:

The error I'm getting:我得到的错误:

error   Named export 'faGithub' not found. The requested module '@fortawesome/free-brands-svg-icons' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:
  
  import pkg from '@fortawesome/free-brands-svg-icons';
  const { faGithub, faLinkedin, faDiscord } = pkg;

Here's my code:这是我的代码:

import {
    faGithub,
    faLinkedin,
    faDiscord,
} from "@fortawesome/free-brands-svg-icons";

Here's my tsconfig.json file:这是我的tsconfig.json文件:

{
    "compilerOptions": {
        "target": "ESNext",
        "module": "ESNext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "types": ["astro/client"]
    }
}

I have been trying to find a solution for this also.我也一直在尝试为此寻找解决方案。

Here is the related bug report: https://github.com/FortAwesome/Font-Awesome/pull/19041这是相关的错误报告: https://github.com/FortAwesome/Font-Awesome/pull/19041

For a quick try if you add "type":"module" into the node_modules/@fortawesome/free-brands-svg-icons/packages.json build works.如果您将“类型”:“模块”添加到 node_modules/@fortawesome/free-brands-svg-icons/packages.json 构建作品中,请快速尝试。

Fix will be included in the next release of the package as mentioned in the bug report.如错误报告中所述,修复将包含在 package 的下一个版本中。 For now I use a dirty hack that changes the free-brand-svg-icons' packages.json file with sed before building.现在我使用一个肮脏的黑客来改变自由品牌svg图标的packages.json文件和sed在构建之前。

Have you tried Astro Icons?你试过天文图标吗? Itś already optimized and you can import all icons from many libraries, including fontawesome as you can see at the icon sets它已经过优化,您可以从许多库中导入所有图标,包括您在图标集中看到的 fontawesome

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM