首页 > 解决方案 > jsconfig.json 允许在 React 中进行绝对导入,但会破坏 Styleguidist 导入

问题描述

jsconfig.json在整个 Create-React-App 中使用绝对导入。有没有办法让 Styleguidist 正确遵守文件定义的绝对导入jsconfig.json?它在我的 React 应用程序中运行良好,但是当 Styleguidist 解析器尝试读取.js文件并遇到这些绝对导入之一时,它无法正确定位它。

jsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src"
  }
}

/src/components/Foo.js

import { Bar } from 'components'

Styleguidist 终端:

Module not found: Cant resolve 'components'
/.
+-- styleguide.config.js
+-- src
|   +-- /components
|   |   +-- Foo.js
|   |   +-- Bar.js
|   |   +-- index.js

请知道我已尝试将 移动styleguide.config.js/src目录中以在该配置和jsconfig.json. 它没有解决问题。

标签: javascriptjsonreactjscreate-react-appreact-styleguidist

解决方案


推荐阅读