开玩笑的transformIgnorePatterns不起作用 [英] Jest transformIgnorePatterns not working
问题描述
我花了很长时间研究有关此问题的其他问题,并查看了Github上的其他项目,但似乎没有一个答案对我有用.
I have spent a long time looking at other questions about this and looking at other projects on Github but none of the answers seem to work for me.
我正在项目中加载第三方库,并且在运行Jest测试时收到错误消息
I am loading a third party library in my project, and when running Jest tests I get the error
export default portalCommunication;
^^^^^^
SyntaxError: Unexpected token export
> 1 | import portalCommunication from 'mathletics-portal-communication-service';
我试图以多种方式更新我的Jest配置,以使其可移植到该库中,但是我总是遇到相同的错误.
I have tried updating my Jest config in many ways to get it to transpile this library but I always get the same error.
这是我当前的jest.config.js文件:
This is my current jest.config.js file:
module.exports = {
moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy',
'\\.svg$': '<rootDir>/test/mocks/svg-mock.js'
},
setupFiles: ['./test/test-setup.js'],
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!mathletics-portal-communication-service)'
]
};
我还尝试添加transform属性以针对此mathletics-portal-communication-service目录运行babel-jest.
I have also tried adding the transform property to run babel-jest against this mathletics-portal-communication-service directory.
请帮助!
推荐答案
直到我将.babelrc更改为babel.config.js,transformIgnorePatterns才对我有用,
The transformIgnorePatterns didn't work for me until I changed my .babelrc to babel.config.js, like this:
module.exports = {
"presets": [
"@babel/preset-env"
]
};
对此评论可见: https://github.com/facebook/jest/issues/6229#issuecomment-403539460
这篇关于开玩笑的transformIgnorePatterns不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!