如何解决使用 ts-jest 在 jest 中转换 esm 文件时遇到问题
所以我一直在思考如何让这些笑话代码转换工作,我在转换 spin.js
esm 文件方面取得了一些进展。那个错误消失后,我转到下一个是 angular-instantsearch
但特别是 angular-instantsearch/node\_modules/instantsearch.js
。这是我收到的错误:
.../node_modules/angular-instantsearch/node_modules/instantsearch.js/es/index.js:2
import algoliasearchHelper from 'algoliasearch-helper';
^^^^^^
SyntaxError: Cannot use import statement outside a module
这是我处理转换的基本笑话配置:
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],transform: {
'^.+\\.(ts|js|html)$': 'ts-jest',},resolver: '@nrwl/jest/plugins/resolver',modulefileExtensions: ['ts','js','html'],coverageReporters: ['html'],transformIgnorePatterns: [
'node_modules/(?!(spin\\.js|instantsearch\\.js/es)/)',],// this caused issues with detecting modules from component files in angular
/* moduleNameMapper: {
"instantsearch\\.js/es$": "instantsearch.js/cjs","instantsearch\\.js/es/(.*)$": "instantsearch.js/cjs/$1",} */
};
对此的任何帮助将不胜感激,谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。