Error: Export keyword unexpectedly found in TypeScript project

Having a problem while running Jest in my TypeScript project. The TypeScript file is located at rootDir/src/_services/index.ts and Jest is throwing an error:

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './auth.service';                                                                                   ^^^^^^

    SyntaxError: Unexpected token 'export'

The issue seems to be with the statement export * from './auth.service'; in index.ts that Jest is having trouble parsing.

My Jest configuration is custom and uses ts-jest. Here is a snippet from the Jest configuration file:

const createJestConfig = nextJest({
  dir: './',
});

const customJestConfig = {
  // ... other configurations ...
  transformIgnorePatterns: [
    '/node_modules/',
    '/@bufbuild/protobuf/',
    '/src/_services/index\\.ts$', // Ignoring this path
  ],
  // ... other configurations ...
};
module.exports = createJestConfig(customJestConfig);

Answer №1

Was there a specific reason for including the third element ('/src/_services/index\.ts$') in this array?:

 transformIgnorePatterns: [
    '/node_modules/',
    '/@bufbuild/protobuf/',
    '/src/_services/index\\.ts$', // should this be removed?
  ],

Because this configuration indicates that the file /src/_services/index.ts will not undergo transformation by any tool and will retain its TypeScript syntax.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An error occurred during the client fetch in next-auth, displaying the message: "[next-auth][error][CLIENT_FETCH_ERROR] Network

Recently, I have encountered an issue while trying to set up Google OAuth using next-auth. The problem arises when attempting to log in using Google as the provider - upon clicking the button, it immediately redirects me to http://localhost:3000/api/auth/e ...

Strange interaction observed when working with Record<string, unknown> compared to Record<string, any>

Recently, I came across this interesting function: function fn(param: Record<string, unknown>) { //... } x({ hello: "world" }); // Everything runs smoothly x(["hi"]); // Error -> Index signature for type 'string' i ...

I'm having trouble inputting text into my applications using React.js and TypeScript

I am encountering an issue where I am unable to enter text in the input fields even though my code seems correct. Can anyone help me figure out what might be causing this problem? Below is the code snippet that I am referring to: const Login: SFC<LoginP ...

What steps are involved in implementing Local fonts in theme UI for Next JS?

I am currently developing an application using next JS with [theme-UI][1]. However, I need to implement local or custom fonts in my project and I'm unsure of how to do this. Below is the current theming setup: const theme = { fonts: { ...

What steps should I take to customize WebStorm so that it no longer automatically imports the entire Typescript paths?

Recently, I noticed a change in WebStorm after an update that affected how paths were imported in my files. Initially, when typing @Component and letting WebStorm automatically import the path, it would use the following format: import { Component } from ...

When using React MUI Autocomplete, make sure to handle the error that occurs when trying to filter options using the

I am trying to implement an autocomplete search bar that makes a custom call to the backend to search through a list of tickers. <Autocomplete multiple id="checkboxes-tags-demo" options={watchlis ...

Issue with const declaration in Typescript and Node.js - initializer is missing

Encountering a syntax error with the following line of code. Error message: SyntaxError: Missing initializer in const declaration const dataMap : Map<string, any> = new Map(); ...

Troubleshooting problem with Electron and TypeScript following recent updates

I recently made updates to my small Electron project using Electron and TypeScript. Here's the code causing issues: dialog.showOpenDialog({}, (files) => { if(files && files.length > 0) { fs.readFile(files[0], 'utf8' ...

What could be causing Typescript Compile Errors to occur during runtime?

In the Visual Studio React + Redux template project, I have created a react component with the following "render()" method: public render() { return ( <React.Fragment> <h1>Welcome to the Adventure Company {th ...

Guidelines for implementing a conditional if-else statement in a props-based Next.js component

I have a Card component, and I would like to implement a condition where if the data is equal to 0, it should display the first image, otherwise it should display the second image. Here's more information: {data?.data?.map((dataVote: any, i: numbe ...

Is it possible to export multiple named exports in a single set without changing how variables are called?

In my constants file I have: export const CONSTANT1 = 'CONSTANT1'; export const CONSTANT2 = 'CONSTANT2'; export const CONSTANT3 = 'CONSTANT3'; export const CONSTANT4 = 'CONSTANT4'; export const CONSTANT5 = 'CONS ...

Testing a service with $resource using unit tests

Struggling to write a unit test for an existing service and puzzled by the unexpected data appearing in the results, leading to test failures. Let's take a look at the key components: Service Method: function createAddressType(newAddressType) { var ...

The Proper Way to Include External CSS in a Next.js Page Without Triggering Any Warnings

I find myself in a scenario where I must dynamically inject CSS into a webpage. The content of this page is constantly changing, and I am provided with raw HTML and a link to a CSS file from a server that needs to be displayed on the page. My attempt to ...

Type A can be assigned to the limitation of type T, although T may be instantiated with a varying subtype constraint of either A or B

I keep receiving this confusing error from TypeScript. My T generic should be fully compatible with types A | B since it extends from it! The error is incorrect in saying that you can't instantiate it with an incompatible type. type MyProps<T exten ...

Executing the GetDoc function multiple times in a React application

Utilizing Firebase for Authentication & Storage and incorporating useContext from react to encase my application with an authentication layer. After retrieving the user from the authentication layer, I proceed to fetch the user's details from Firesto ...

What is the best approach for manipulating live data in localStorage using ReactJS?

I am working on creating a page that dynamically renders data from localStorage in real-time. My goal is to have the UI update instantly when I delete data from localStorage. Currently, my code does not reflect changes in real-time; I have to manually rel ...

Upcoming topics - The Challenge of Staying Hydrated at Basecamp One

I have implemented a themes package for dark mode and light mode in my project. Despite doing the installation correctly as per the repository instructions, I am encountering an issue. My expected behavior for the project is: The webpage should initially ...

Receiving a 405 error when making an API call - could the routing be misconfigured? (Using NextJS and Typescript)

Hey there, I've been working on implementing a custom email signup form that interfaces with the Beehiiv newsletter API. If you're interested, you can take a look at their API documentation here: Beehiiv API Docs Currently, my web application i ...

What are the best practices for styling a component in Fluent UI when using React and TypeScript?

I'm attempting to set a background color for this specific div element: import * as React from 'react' import { Itest } from '../../../../../models' import { getPreviewStyles } from './preview.style.ts' type IPreviewP ...

Create a class where each method is required to be a "getter" function

Is it feasible to establish a class in which all methods must be getters? Possible Implementation: class Example implements AllGetters { get alpha () { } get beta () { } } Not Acceptable: class Example implements AllGetters { get alpha () { ...