我将一个依赖包拉入我的node_modules文件夹中。这个包含有一个导出,像这样:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './client';
为了解决这个问题,我使用了https://github.com/standard-things/esm。在我的node加载器中使用:
node -r esm index.js
。但是,这对于使用Jest的测试不起作用。我似乎无法弄清楚如何让Jest为我转换这些导入。我尝试了很多方法,但目前配置文件的状态如下:// babel.config.js
// babel.config.js
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
plugins: ['@babel/plugin-transform-modules-commonjs'],
};
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/**/*.{ts,js}'],
testPathIgnorePatterns: ['global.d.ts', 'utils.ts', '<rootDir>/node_modules/'], // tried with and without this
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
};
依然收到该错误。 有人有建议吗?