繁体   English   中英

使用根导入插件在Gatsby中为NPM软件包创建别名

[英]Creating an Alias for an NPM Package in Gatsby Using the Root Import Plugin

我已经安装了gatsby-plugin-root-import插件来为我的Gatsby网站中gatsby-plugin-root-import创建别名。 我已经使用了一段时间了,效果很好。

今天,我决定看看是否可以将其用于已安装的npm软件包。 我想我正确设置了它,但是却收到一条错误消息,说找不到该模块:

Module not found: Error: Can't resolve 'FontAwesome' in '/sandbox/src/pages'

但是,当我查看自己的代码时,它似乎应该可以工作:

{
      resolve: 'gatsby-plugin-root-import',
      options: {
        // Node Modules
        FontAwesome: path.join(__dirname, '@fortawesome/react-fontawesome'),

        // Main Folders
        SRC: path.join(__dirname, 'src'),
        Assets: path.join(__dirname, 'src/assets'),
        Components: path.join(__dirname, 'src/components'),
        Config: path.join(__dirname, 'src/config'),
        Layouts: path.join(__dirname, 'src/layouts'),
        Pages: path.join(__dirname, 'src/pages'),
        Plugins: path.join(__dirname, 'src/plugins'),
        Styles: path.join(__dirname, 'src/styles'),
        Utilities: path.join(__dirname, 'src/utilities'),

      },
    },

所有其他别名都可以正常工作-只有FontAwesome别名会创建模块未找到错误消息。

知道为什么这行不通吗,我该怎么做才能解决?

谢谢。

PS这是插件的链接: https : //github.com/mongkuen/gatsby-plugin-root-import

我认为问题在于:

FontAwesome: path.join(__dirname, '@fortawesome/react-fontawesome'),

您将仅使用node_modules中插件的名称加入根文件夹。 但是您需要查看node_modules文件夹,因为它不会像导入一样自动解决。

您可以改为测试以下行吗?

FontAwesome: path.join(__dirname, 'node_modules/@fortawesome/react-fontawesome'),

暂无
暂无

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

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