Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

angular - Trouble transforming esm files in jest with ts-jest

So I have been banging my head on how to get these jest code transforms to work and I have made a bit of progress with transforming the spin.js esm files. With that error gone I moved on to the next one which was angular-instantsearch but specifically angular-instantsearch/node\_modules/instantsearch.js. Here is the error I am reciving:

.../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

Here is my base jest config that deals with the transforms:

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",
  } */
};

Any help on this will be extremely appreciated, thanks!

question from:https://stackoverflow.com/questions/65907329/trouble-transforming-esm-files-in-jest-with-ts-jest

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...