1

I have a create-react-app project with TypeScript. I recently added a couple of packages (specifically material-ui-dropzone and @azure/storage-blob) to my project, and suddenly all my tests are failing because of a SyntaxError in a file I haven't really touched. I've seen other people having problems with es6 imports and babel transformation, but this error seems a little different. yarn start and yarn build work without any problems. Here's the output from yarn test:

/<projectPath>/src/Shared/utils/authorizer.ts:27
    private constructor() {
            ^^^^^^^^^^^
SyntaxError: Unexpected identifier
     9 | import Log from 'Core/debugLog/Log';
    10 | import { Guid } from 'guid-typescript';
  > 11 | import { Authorizer } from 'Shared/utils/authorizer';
       | ^
    12 | import { AppInsights } from 'Shared/utils/appInsights';
    13 | import { OperationDefinitionNode } from 'graphql';
    14 |
    at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
    at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
    at Object.<anonymous> (src/Core/graphql/graphQlConfig.ts:11:1)

In my jest config in package.json I have only a couple of configs related to coverage.

I tried running yarn upgrade, and noticed a lot of babel dependencies upgrading from 7.5.5 to 7.7.2, but the same problem persists.

Please ask if there is any other information I can give to help diagnose the problem.

1 Answer 1

1

I finally solved this by adding ts-jest:

yarn add -D ts-jest

And adding this under "jest" in package.json:

"transform": {
  "^.+\\.tsx?$": "ts-jest"
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.