我创建了一个名为 的包@package/test。当导入到新的空 React typescript 应用程序时,效果非常好。问题始于 Jest 测试套件。
包commonJS版本导致 Jest 抛出:
Test suite failed to run. TypeError:Cannot read property 'getSelectors' of undefined
import { Test } from `@package/test
const selectors = Test.getSelectors(...); //error here indicating that Test is undefined
Run Code Online (Sandbox Code Playgroud)
当我编译ES modules软件包版本时,它会导致 Jest 抛出
export * from './common';
^^^^^^
SyntaxError: Unexpected token export
Run Code Online (Sandbox Code Playgroud)
src/index.ts这是我的包裹里面的第一行。
我测试过很多解决方案,例如:
transformIgnorePatterns为玩笑定义eslint使用插件搜索循环依赖关系Madge有关该包的一些详细信息:
export * from './common';
^^^^^^
SyntaxError: Unexpected token export …Run Code Online (Sandbox Code Playgroud)