Babel does not process every single file for compilation

I recently started a project using Babel 7 with Typescript. Combining these two technologies was a bit of a challenge, but I finally got it working. However, there's still one issue that I'm facing.

During the compilation of my project, all .ts files from ./src/ are converted to .js files in ./dist/. Dotfiles are correctly ignored, as expected. But I noticed that any files without the .ts extension in ./src/ are also being ignored.

I've tried several different commands to resolve this:

// package.json
"scripts": {
    // build1 only compiles the .js files
    "build1": "babel src --out-dir dist",
    
    // build2 only compiles the .ts files
    "build2": "babel src --out-dir dist --extensions \".ts\"",
   
    // build3 only compiles the .ts files
    "build3": "babel src --out-dir dist --extensions \".ts, .js\"", 
    
    // build4 only compiles the .js files
    "build4": "babel src --out-dir dist --extensions \".js, .ts\""
},

Below is my babel config file

// babel.config.js
module.exports = {
  presets: [
    "@babel/env",
    "@babel/typescript",
  ],
  plugins: [
    "transform-dynamic-import",
    "@babel/proposal-class-properties",
    "@babel/proposal-object-rest-spread"
  ],
};

Any suggestions?

Thank you!

Update: I discovered that removing the space in the --extensions argument resolves the issue, but it has introduced a new problem. Now, when running the command

"babel src --out-dir dist --extensions \".ts,.js,.json\""
, .json files are also getting converted to .js. My goal is for Babel to transform .ts to .js, compile the .js files, and simply copy any other file as is.

Answer №1

After much searching, I finally discovered the solution. In order to successfully complete the task, I realized that it was necessary to include the --copy-files argument in the command.

By executing the following command: babel src --out-dir dist --extensions \".ts,.js\" --copy-files

Specifying --extensions \".ts,.js\" directs babel to compile all files with .ts and .js extensions.

Additionally, using --copy-files instructs babel to duplicate all remaining files as well.

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

Tips for integrating dynamic external components into Angular applications

I have encountered an issue with my Angular application. My goal is to create an Angular application written in TypeScript and built with (aot). The objective is to create a user dashboard with various widgets, each widget being an Angular component. Wh ...

There seems to be an issue with the Angular zone.js and zone-evergreen.js files showing an error that reads:

My Angular 11 app suddenly started showing errors across all browsers and environments (local, staging, prod) about an hour ago without any updates: Uncaught TypeError: t.getElementsByTagName is not a function at computeStackTrace.js:338 at Array.f ...

Endless Scroll using Typescript and Angular 4

I'm currently in the process of setting up an angular4 application, pulling data from an API. I'm working on implementing an easy infinite scroll feature, and while it's functioning properly, the initial page content is being loaded twice. H ...

Combining images and text from diverse sources

I'm currently engaged in some web scraping, attempting to extract both the image and text from different classes, and then showcase them together. Below is an example of the HTML snippet: <div class="thumbnail"> <div class="i ...

The Bootstrap modal I implemented is opening correctly, but for some reason, the form inside is not appearing

I created the AddJokeModalComponent to streamline the process of opening a form without duplicating code in every component. Below is the modal structure: <ng-template #addJokeModal> <div class="modal-content my-custom-modal"> ...

Utilize Optional Chaining for verifying null or undefined values

I have utilized the following code: data?.response[0]?.Transaction[0]?.UID; In this scenario, the Transaction key is not present, resulting in the error message: ERROR TypeError: Cannot read properties of undefined (reading '0') Instead of chec ...

Error: Unable to modify a property that is marked as read-only on object '#<Object>' in Redux Toolkit slice for Firebase Storage in React Native

Hey there! I've been working on setting my downloadUrl after uploading to firebase storage using Redux Toolkit, but I'm facing some challenges. While I have a workaround, I'd prefer to do it the right way. Unfortunately, I can't seem to ...

Style will be applied to Angular2 when the object's ID exceeds 100

I am working with object markers that have different Id's assigned to them. Now, I am trying to apply additional styling when the id > 100. Check out the code snippet below: <span *ngIf="result.object.reference > 100" class="tooltip-data"&g ...

Creating number inputs in Ionic 2/3 using alerts

I am currently working with Ionic 3.x on my macOS system. The issue I am facing is as follows: I have an array that contains a number and another array consisting of names. table: { number: number, names: string[] } = { number: 0, names: ['& ...

What is the best way to execute a sequence of http requests only after the previous one has been completed successfully, while also addressing any

Working with Angular/rxjs 6 has brought me to a challenge. I'm struggling to get an observable sequence to run smoothly as intended. Here's the concept of what I'm trying to achieve: Request received to change systems: Check permissions Fe ...

Tips for updating the front end with the status of a lengthy playwright test

In the node backend, I have defined a route for test progress using SSE (https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events). The URL initialization is happening on the frontend. Below is the code snippet from th ...

transferring data from service to component

Dealing with the challenge of passing a variable from a service (LibraryService) to a component located one level deeper in the directory structure (ReadingPaneComponent) has been quite troublesome for me. This predicament arose after successfully transfer ...

The value of an Angular rxjs BehaviorSubject can be updated using the value property directly, without calling

While testing my code, I stumbled upon unexpected mutation. Perhaps I am doing something wrong. User constructor( public id: number, public education: Education[] ){} UserStateService private user = a new BehaviorSubject<User>(null); setUser(us ...

Error: Unable to access the property of an undefined variable in Angular 4

Here is what I currently have in my code: <p *ngIf="model.something.satisfy"> Yes </p> <p *ngIf="!model.something.satisfy"> {{model.something.comments}} </p> The issue arises in the second line with the error message "Type ...

Issue with displaying data using a custom pure pipe and boolean in ngIf condition

For my current web project, I require a friendship/follow feature. There are two roles involved: admins and regular users. Regular users have the ability to follow other users, while admins do not possess this capability. When a user wishes to follow anot ...

Issue: Compilation error encountered when attempting to build module (from ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js):

I encountered an issue while trying to set up Angular Material. Initially, I received an error message. I attempted to resolve it by deleting the node modules and running npm i again, but the problem persists. How can I rectify this? Upon trying to launch ...

Can anyone provide guidance on incorporating lodash into an Ionic 2 project?

Recently, I began diving into a new project that involves Ionic 2. TypeScript is still fairly new to me, and I've been brainstorming ways to integrate lodash into my project. Have any of you tackled this before and can offer guidance on how to achiev ...

The ActivatedRoute snapshot does not function properly when used in the TypeScript class constructor

Currently, I am encountering a challenge with TypeScript and Angular 2. The structure of my TS class is as follows: 'import { Component, OnInit } from '@angular/core'; import {ActivatedRoute} from '@angular/router'; @Component({ ...

Steps to create an instance method that only accepts the name of another instance method

I am looking to enhance an object by adding a method that specifically accepts the name of another method within the object. How can I achieve this in a way that dynamically narrows down the accepted names of methods, without hardcoding them? Let's t ...

ESLint flagging "Unexpected tab character" error with "tab" indentation rule enabled

Currently, my ESLint setup includes the Airbnb plugin (eslint-config-airbnb) along with the Babel parser. I recently decided to enforce the rule of using Tab characters for indentation instead of spaces. This is how my .eslintrc file looks like: { "p ...