Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
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';
I have tried updating my Jest config in many ways to get it to transpile this library but I always get the same error.
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)'
I have also tried adding the transform property to run babel-jest against this mathletics-portal-communication-service directory.
Please help!
–
The transformIgnorePatterns
didn't work for me until I changed my .babelrc
to babel.config.js
, like this:
module.exports = {
"presets": [
"@babel/preset-env"
as seen on this comment: https://github.com/facebook/jest/issues/6229#issuecomment-403539460
–
–
–
Another team at my org added some common module. This was not transpiled and so the issue.
I followed this: https://babeljs.io/docs/en/configuration#whats-your-use-case
Converted my .babelrc
to babel.config.json
in jest config added this:
transformIgnorePatterns: ['/node_modules/(?!(@companyName)/).*/'],
This solved my problem.
As a workaround for now I have changed my config to use the moduleNameMapper
option to load a mock class for that library instead. I would have preferred to use transformIgnorePatterns
instead so would still appreciate any ideas.
New config:
module.exports = {
moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy',
'\\.svg$': '<rootDir>/test/mocks/svg-mock.js',
'mathletics-portal-communication-service': '<rootDir>/test/mocks/mathletics-portal-communication-service-mock.js'
setupFiles: ['./test/test-setup.js']
// ...
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!mathletics-portal-communication-service/)'
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.