The process of file transformation using es6-transform-karma-typescript can sometimes result in karma encountering an obstacle



I'm currently in the process of setting up a unit testing framework using typescript, karma, and mocha. I am utilizing karma-typescript for transpiling and es6-transform-karma-typescript to convert es6 code to browser-compatible es5 code. However, my progress seems to be halted at this particular line:

16 08 2021 19:34:35.898:INFO [compiler.karma-typescript]: Compiled 64 files in 6103 ms.
16 08 2021 19:34:36.422:DEBUG [bundler.karma-typescript]: Project has 247 import/require statements, code will be bundled
**16 08 2021 19:34:36.500:DEBUG [es6-transform.karma-typescript]: Transforming /Users/test/sourcecode/test-web-ui/src/app/Memory.js**

Below are the settings from my tsconfig.json file and karma.conf file.

karma.conf:

const {dirname, join, resolve} = require("path");

module.exports = (config) => {
    config.set({
        plugins: ['karma-chrome-launcher', 'karma-mocha', 'karma-typescript', 'karma-webpack', 'webpack','karma-mocha-reporter'],
        frameworks: ['mocha', 'karma-typescript'],
        preprocessors: {
            "**/*.ts": ["karma-typescript"],
            "**/*.tsx": ["karma-typescript"] // *.tsx for React Jsx
        },
        logLevel: config.LOG_DEBUG,
        browsers: ['Chrome'],
        singleRun: true,
        autoWatch: false,
        color:true,
        reporters: ["mocha", "karma-typescript"],
        files: [{ pattern: "src/**/*.ts" }, {pattern: "src/**/*.tsx" }],
        karmaTypescriptConfig: {
            stopOnFailure: true,
            bundlerOptions: {
                acornOptions: {
                    ecmaVersion: 8,
                  },
                transforms: [
                    require("karma-typescript-es6-transform")({
                        presets: [require("@babel/preset-env")]
                    })
                ]
            },
            compilerOptions: {
                target: "ES2015",
                lib: ["ESNext", "dom"],
                module: "CommonJS",
                incremental: false
            },
            tsconfig: "testing.tsconfig.json"
        }
    });
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "ES2017",
        "module": "CommonJS",
        "incremental": true,
        "noUnusedParameters": false,
        "sourceMap": true,
        "jsx": "react",
        "strict": true,
        "esModuleInterop": true,
        "declaration": true,
        "declarationMap": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "lib": [
          "dom",
          "dom.iterable",
          "esnext"
        ],
        "allowJs": true,
        "allowSyntheticDefaultImports": true,
    
        "noFallthroughCasesInSwitch": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true
      },
    "include": ["src/**/*.ts","src/**/*.tsx"],
    "exclude": ["node_modules"]
}

To run the tests, I have included the following command in my package.json file:

"test": "karma start karma.conf.js --log-level=DEBUG",

If anyone could assist in identifying the issue, that would be greatly appreciated.

Answer №1

Dealing with this issue has been a challenge for me and it's been quite frustrating. After some research, I was lucky enough to stumble upon the solution here. It turns out that having "acorn" running on version 8 or using "karma-typescript-es6-transform" is key.

The interesting part is that the link provided above mentions that the problem has already been fixed. And indeed it has! By checking your package-lock.json and searching for "acorn", you'll likely come across multiple dependencies requiring "acorn". Look out for "karma-typescript-es6-transform" which specifically needs "acorn" with a version of ^8.x.x. Despite this adjustment, my compilation process still hit a snag.

The issue arose from my primary "acorn" dependency being stuck on version ^7.x.x. Even though "karma-typescript-es6-transform" stipulated a higher version, node failed to adhere to this requirement and defaulted to the older version of "acorn".

To work around this problem, I opted to install acorn as a dev-dependency to ensure that I obtained the latest version: npm i --save-dev acorn Give it a shot!

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

Can someone please explain how to prevent Prettier from automatically inserting a new line at the end of my JavaScript file in VS Code?

After installing Prettier and configuring it to format on save, I encountered an issue while running Firebase deploy: 172:6 error Newline not allowed at end of file eol-last I noticed that Prettier is adding a new line at the end when formatting ...

Tips for bringing in specialized document formats in Typescript

For a fun side project, I am in the process of creating a "framework" to easily develop native web components. One aspect of this involves using a webpack loader to parse XML within custom .comp files and export an es2015 class. However, I've encounte ...

Troubleshooting error "is not assignable to type..." when simulating global fetch using TypeScript

I am encountering an issue with the "global.fetch" part and cannot seem to figure out why. Despite following the standard procedure, I am still facing this TS2322 error. I am seeking assistance to understand why this error is occurring. I am open to sugges ...

Oops! Looks like you forgot to provide a value for the form control named <name>. Make sure to fill

I have encountered an issue with a nested operation. The process involves removing an offer and then saving it again as a repeating one. However, the problem arises when I try to use patchValue() on the item in offerList[index] after saving the repeating ...

If the outer observable encounters an error, make sure to forcefully call the inner observable within the switchMap

Here is my code: return this.userService.getPosition().pipe( switchMap(() => { return this.get('/places', { point: this.userService.coords }); }), ); Sometimes, the position cannot be retrieved, for example if the ...

Can the performance of an angular 6 application be slowed down by loading the same bootstrap css file multiple times?

In my Angular 6 application, I noticed that Bootstrap is being loaded multiple times - once in the src/index.html file and then again in each component's .ts file. <link href="assets/css/bootstrap/css/bootstrap.css"> styleUrls:[ ...

Tips for successfully accessing a variable in an Angular Pipe

When displaying output, I need to show a specific number of decimal digits based on the length returned by a stored procedure. The length of these decimal digits can vary, and I only need to focus on the decimal part, not the integer part. To achieve this, ...

Tips for retrieving input values when they are not available in HTML documents

In this code snippet, I am creating an input element with the file type without adding it to the DOM. My goal is to retrieve the value of this input once the user selects a file. Even though the input is not part of the HTML template, I still want to acces ...

Developing custom events in an NPM package

Developing a basic npm package with signalr integration has been my recent project. Here's how it works: First, the user installs the package Then, the package establishes a connection using signalr At a certain point, the server triggers a function ...

The type 'string | AddressInfo' does not include a 'port' property and does not have a string index signature

When running in { port }, I encountered the following error: Type 'string | AddressInfo' has no property 'port' and no string index signature. How can I resolve this issue? Code: import * as express from 'express' const app ...

Separate an array in TypeScript based on the sign of each number, and then replace the empty spaces with null objects

Hey, I'm facing a little issue, I have an Array of objects and my goal is to split them based on the sign of numbers. The objects should then be dynamically stored in different Arrays while retaining their index and getting padded with zeros at the b ...

The class constructor in the TSdx package must be invoked with the 'new' keyword

I recently developed a npm package using TSdx to create a small Jest reporter. However, when I try to use this package in another project, an error occurs. Uncaught TypeError: Class constructor BaseReporter cannot be invoked without 'new' at ...

Issue with NGRX effect not persisting changes to the state within the store

We have an API boolean setting that we want to cache after the initial call. To achieve this, I created an effect that sets the value when a new instance of appSettings (our application-wide settings) is added: public checkCachedEffectg$ = createEffect(( ...

Can you explain the significance of the "@" symbol in the `import from '@/some/path'` statement?

When I use IntelliJ IDEA to develop a web application in TypeScript, the autocomplete feature suggests imports from other files within my project like this: import {Symbol} from '@/components/Symbol'; I am curious about the significance of the @ ...

Understanding the export and export default behavior in JavaScript

I am in the process of developing a NodeJS and Express application and I require a configuration module that executes only once during startup and then provides a serverConfig object to any other modules that may need these values. This is what I have so f ...

Convert JSON data to an array using Observable

My current task involves parsing JSON Data from an API and organizing it into separate arrays. The data is structured as follows: [ {"MONTH":9,"YEAR":2015,"SUMAMT":0}, {"MONTH":10,"YEAR":2015,"SUMAMT":11446.5}, {"MONTH":11,"YEAR":2015,"SUMAMT":5392 ...

Angular: The fetched data from the API is coming back as undefined

I am trying to use the Highcharts module in Angular to build a chart. The data object needed for the chart is provided by an API, and this is the structure of the object: { "success": true, "activity": [ { &q ...

What causes the inaccessibility of methods added via decoration?

Let's say I have a Directive decorator that adds a static method called factory to its target: function Directive<T extends { new (...args: any[]): {} }>(constructor: T) { return class extends constructor { static factory(...args): ng.IDi ...

Exploring React Router along with Protected Route and onboarding features

I recently developed a React application with a Signin process, onboarding flow, and a dashboard. The onboarding process consists of two pages: org-creation and invite-member. Sign in functionality is managed by Aws Amplify and includes Google sign-in. Bel ...

Extra assistance might be required to manage the output from these loaders

I'm in the process of developing a State Management Library for ReactJs. However, when I integrate it into my React project (built with create-react-app), an error is thrown: Failed to compile. path/to/agile/dist/runtime.js 116:104 Module parse faile ...