所以我有一個依賴包,我將它拉到我的 node_modules 文件夾中。這個包有一個像這樣的導出 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './client';為了解決這個問題,我使用https://github.com/standard-things/esm。在我的節點加載器中node -r esm index.js.但是,這不適用于我使用 Jest 的測試。我似乎無法弄清楚如何讓 Jest 為我轉換這些導入。我已經嘗試了很多東西,我的配置文件的當前狀態是。// babel.config.js// babel.config.jsmodule.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>/' }),};仍然不斷收到該錯誤。任何人都有一個建議。
我如何開玩笑地使用 ES6 依賴項
肥皂起泡泡
2021-10-14 17:00:44