为什么在运行 Jest 并导入 ESM 模块时我的模块是一个空的 {}?

问题描述

我正在从导出 ESM 模块的 node_module 包中导入认导入。我已经设置了我的 Jest/Babel,使它不再抱怨 SyntaxError: Unexpected token import,但是现在它成功导入了模块,结果发现该模块是一个空对象。我需要以某种方式转换我的代码吗? (P.S. 这可能不言而喻,但导入在我的应用中运行良好。)(P.P.S. 我正在使用 Create React App 和 TypeScript,以防万一。)

jest.config.js

module.exports = {
  moduleNameMapper: {
    '\\.(css|less)$': 'identity-obj-proxy',},preset: 'ts-jest',transformIgnorePatterns: ['node_modules/(?!(@micro-frontend-apps)/)'] // this successfully allows the ESM module to be imported without complaint
};

styles.ts(正在测试)

import { theme } from '@micro-frontend-apps/design-systems-library';
import styled from 'styled-components';

const InputContainer = styled.div`
  .react-tel-input {
    font-family: ${theme.font.fontFamilyBrand}; // *theme is undefined here*
    li {
    ...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...