reactjs - ทำไมโมดูลของฉันถึงเป็น {} ว่างเมื่อรัน Jest และนำเข้าโมดูล ESM?
ฉันกำลังนำเข้าการนำเข้ามาตรฐานจากแพ็กเกจ node_module ที่ส่งออกโมดูล ESM ฉันได้ตั้งค่า Jest/Babel ของฉันเพื่อให้มันหยุดแจ้งข้อผิดพลาด SyntaxError: Unexpected token import แต่ตอนนี้เมื่อนำเข้าโมดูลสำเร็จแล้ว ปรากฏว่าโมดูลนั้นเป็นวัตถุว่าง ฉันจำเป็นต้องแปลงโค้ดของฉันบางอย่างหรือไม่? (ป.ล. คงไม่ต้องบอก แต่การนำเข้าทำงานได้ดีในแอปของฉัน) (ป.ป.ล. ฉันใช้ 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 {
...