Having trouble getting the Babel plugin transform-remove-console to function properly with the Vue CLI 4 and @vue/cli-plugin-babel/preset?

When you create a VueJS project using Vue CLI 4, Babel is configured with a useful preset in babel.config.js:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
  ],
};

I am attempting to use babel-plugin-transform-remove-console to eliminate console.* statements from the JavaScript files generated.

I installed the plugin as a development dependency using:

npm i -D babel-plugin-transform-remove-console

Then I made modifications to babel.config.js:

module.exports = (api) => {
  var env = api.cache(() => process.env.NODE_ENV);
  var plugins = [];
  // Switch to 'production' once configurations are finalized
  if (env === 'development') {
    plugins.push(['transform-remove-console', { exclude: ['error', 'warn'] }]);
  }
  return {
    presets: ['@vue/cli-plugin-babel/preset'],
    // plugins,
    // Even when always enabled?
    plugins: ['transform-remove-console'],
  };
};

This setup should work by running npm run serve -- --reset-cache, and I've attempted building the app multiple times with various environments, but the console logs continue to appear in the browser's console?

Could it be that Vue CLI's preset is causing issues with setting plugins through this configuration file?

UPDATE: I have submitted a bug report to the Vue CLI repository, and while creating a minimal reproducible bug repository, I discovered that this plugin works with a new project.

However, I am unsure what is causing this problem as I have synced this application with the latest CLI bootstrapped template, and also tried clearing the NPM cache by running `npm cache clean --force`.

Answer №1

Encountered a similar issue myself. Initially, the following method did not resolve it:

plugins: ['transform-remove-console']

However, implementing this alternative approach worked like a charm:

plugins: [['transform-remove-console', { exclude: ['error', 'warn'] }]]

Hoping this solution proves useful to others facing the same challenge.

Answer №2

Following @Zydnar's advice to delete the node_modules folder seemed to have resolved the issue, but upon further investigation, I discovered that my recent NPM package updates were incomplete due to interruptions. I noticed discrepancies in versions of Vue CLI plugins.

After deleting node_modules and updating all packages, the Babel plugin started functioning properly!

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

Connecting event listeners to offspring elements, the main element, and the entire document

My request is as follows: I have multiple boxes displayed on a webpage, each containing clickable divs and text. When a user clicks on a clickable div, an alert should appear confirming the click. Clicking on the text itself should not trigger any action. ...

Validating dates in TypeScript

Currently, I am studying date handling and have an object that contains both a start and end date. For example: Startdate = "2019-12-05" and Enddate = "2020-05-20" My goal is to establish a condition that first verifies the dates are not empty. After tha ...

Simulating an ES6 module that returns a factory function for moment.js

Disclaimer: I'm a beginner with Jest so please bear with me. I'm currently working on testing a Vue2.js filter named DateFilter using Jest. This filter simply formats a date that is passed to it. DateFilter.js import Vue from 'vue'; ...

"Troubleshooting Why AJAX Update for CGridView is Not Functioning

I've encountered an issue with my CGridView grid where I receive an error every time I try to update it. Despite spending a lot of time trying to resolve this, I still haven't been able to figure out what's missing. Here's the code sni ...

Make sure the page preloader is visible before any other content is loaded

Currently, I am working on a straightforward preloader page that remains visible until the main content of the page is completely loaded. Despite the functionality of the loading page, my main concern lies in the quick display of the main content before th ...

What methods can be used to circumvent test coverage for external or dependency Vue components?

We're facing an issue with our two Vue3 projects. Project 1 relies on components imported from Project 2 as dependencies. Within Project 1, MyComponent.vue: <template> <Project2Modal> Some html here </Project2Modal> </template& ...

Repeating items must be unique; duplicates are not permitted on ng-repeat

The data retrieved from the service request is in JSON format and looks like this: { "entries": [{ "id": 2081, "name": "BM", "niceName": "bodmas" }] }, { "id": 8029, "name": "Mas", "niceName" ...

Differences between React Router's createBrowserRouter and Browser RouterWhen it

As I embark on a fresh React endeavor, my goal is to incorporate the most up-to-date version of React Router. According to the documentation, createBrowserRouter is the preferred choice for web projects. While they mention that it allows for certain data A ...

The online server is unable to access the route from the ajax function in a separate JavaScript file

I am currently working on a Laravel project where each view page has its own separate JS file. However, I have encountered an issue when trying to access route functions from AJAX post or get calls on the online server (Digital Ocean). The error message I ...

Retrieving Firestore information as a JavaScript object

I'm working on retrieving data from Google Firestore as a JavaScript object in Vue.js (3). It functions correctly when used within a V-for loop, but I also need to utilize the array in methods. How can I convert the Firestore data into a basic JavaScr ...

React Jodit Editor experiencing focus loss with onchange event and useMemo functionality not functioning properly

I'm currently working on a component that includes a form with various inputs and a text editor, specifically Jodit. One issue I've encountered is that when there are changes in the Jodit editor's content, I need to retrieve the new HTML va ...

"Utilizing JSON.parse() to convert a string captured from a PythonShell back

Using PythonShell in Node to execute a Python script that generates a Python dict, such as: { "playedStatus": game['playedStatus'].encode('ascii'), "awayTeamAbb": game['awayTeamAbb'].encode('ascii'), "homeTeamAbb": ...

Ensure that all content is completely loaded before displaying it using Angular 2

As an Angular developer, I am facing a challenge in my component where I am generating an image through a service HTTP call. Unfortunately, the image generation process takes longer than the site load time, causing the image to not appear immediately on th ...

I am looking to obtain a value through a JavaScript function that sums values upon clicking. The result is satisfactory, but I am seeking a way to limit the value

I only need 2 decimal values, not large ones. Can someone please help me achieve this? <script> $(function() { $("#isum, #num1, #num2, #num3, #rec1, #rec2, #rec3, #difnum1, #difnum2, #difnum3").on("keydown ke ...

What steps do I need to take in order to generate a legitimate link annotation within Adobe Acrobat by utilizing Acrobat

Seeking guidance on how to embed an Acrobat Javascript within Adobe Acrobat in order to generate a link annotation. The current method involves using the "addLink" function within the document object, which triggers a Javascript action upon clicking the li ...

Is there a way to specifically call the last promise in a loop?

I'm new to promises and could use some help. I have a situation where promises are resolving randomly, how can I ensure that the last promise in the loop is resolved after the full loop executes? For example, if this.selectedValues has 4 values, som ...

Error: FullCalendar does not display a header for the timeGridWeek view when the dates fall

Currently, I am integrating fullcalendar 5.5.0 with Angular 10. After migrating from fullcalendar v4 to v5, I noticed an annoying issue where the header for the date before the validRange start is no longer displayed: https://i.sstatic.net/kvVUW.png Thes ...

What is the best way to reach App.vue from a different component?

Within my VueJs 2 app, I have the following code in the Vue.app: export default { name: 'app', data () { return { title: 'Supplier Management', supplierId: '' } }, methods: { loadFunction (rou ...

Error message: App not defined in Ember App.router

Attempting to set up routing for my app for the first time, but struggling to grasp the logic. I managed to render my templates by adding the following code to my route.js file: import Ember from 'ember'; import config from './config/enviro ...

Best method for removing CrosshairMove event listener in lightweight charts

As per the documentation, using unsubscribeCrosshairMove allows us to remove a handler that was previously added with subscribeCrosshairMove. Our objective is to use unsubscribe... to eliminate previous handlers before re-subscribing with subscribe... af ...