-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest encountered an unexpected token #4267
Comments
I have a similar issue. It seems to me that for some reason ts-jest instructs the typescript compiler to emit ES3/ES5 code. I cannot pinpoint where this is happening though |
This error indicates that Jest tried to process Usually, this can be solved by configuring You can also use Jest ESM mode to process ESM axios file. |
I think I'm having the same issue https://github.com/karpikpl/typescript-esm-sample SyntaxError: Cannot use import statement outside a module
> 1 | import { graphql } from '@octokit/graphql' this seems to have no effect: "transformIgnorePatterns": [
"node_modules/(?!(@octokit/graphql|@octokit/request))"
], |
I am having a similar issue. In my case I see that for the node_module in question the TS compiler outputs: {
"outputFiles": [],
"emitSkipped": true,
"diagnostics": []
} This then causes ts-jest to output the message.
Please see the README in the repository for more information. |
@thenoseman you can use this workaround
|
I cannot thank you enough, that drove me nuts for two days! |
That didn't seem to work for me
|
Detail:
I have updated a third party library axios version to 1.6.7 . When I ran tests I started to get the following error
` Jest encountered an unexpected token
package.json
jest.config.js
`const { jest: lernaAliases } = require('lerna-alias');
module.exports = {
preset: 'ts-jest',
moduleNameMapper: lernaAliases(),
transform: {
'^.+\.tsx?$': 'ts-jest', // Add TypeScript transformation
'^.+\.jsx?$': 'babel-jest', // Add Babel transformation for ES6 modules
},
coverageReporters: [['lcov', { projectRoot: '../../' }]]
};
`
The text was updated successfully, but these errors were encountered: