网站搜索

reactjs - React styled-components 使用宏时 TypeError:无法读取未定义的属性(读取 'path')


我有一个使用 TypeScript 的 React 项目,我正在尝试从 Windows 10 切换到 Ubuntu 20.04。在 Windows 上我的项目运行正常。但是在 Ubuntu 上,当我尝试用 npm run start 运行它时,我收到这个错误:

TypeError: /home/dragos/Desktop/project/frontend/src/components/Component.style.ts: Cannot read properties of undefined (reading 'path')

如果我从 import styled from 'styled-components/macro' 中移除 /macro 部分,像这样 import styled from 'styled-components',项目就可以正常运行了。但我不想这样做,因为我是团队的一员,其他人可能需要那功能。

Node 版本(16.13.0)和 npm 版本(7.24.1)在 Windows 和 Ubuntu 上都是相同的。

有人以前遇到过这个吗?

编辑:我添加了 Component.style.ts:

import { H1, H3 } from 'components';
import styled from 'styled-components/macro';

export const Img = styled.img`
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
`;

export const ImgContainer = styled.div`
  display: block;
  width: 58rem;
  height: 28rem;
  position: relative;
`;

export const TitleIpad = styled(H1)`
  @media (max-width: 767px) {
    display: none;
  }
`;