What is the process for transpiling async/await to ES5?

When trying to compile async..wait to es5, I encountered an issue where a folder with a package.json cannot be compiled. I have searched for a solution on Google multiple times but have been unsuccessful. Can someone please provide guidance on how to resolve this? Your help is greatly appreciated!

Directory Structure enter image description here

.babelrc

{
  "presets": [
    [ "@babel/preset-env" ],
    [ "@babel/preset-react"]
  ],
  "plugins": [
    ["@babel/plugin-transform-runtime", { "corejs": 3}],
    "transform-class-properties",
    ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": true}, "antd"]
  ]
}

webpack.config.js

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

function resolve(dir) {
  return path.resolve(__dirname, '..', dir)
}
module.exports = {
  mode: 'production',
  entry: './src/pdfjs-dist1/build/pdf.js', // compiled, no package.json
  // entry: './src/pdfjs-dist2/build/pdf.js', // NO compiled, include package.json
  output: {
    path: resolve('./dist'), // 打包后的文件存放的地方
    filename: 'js/[name].[chunkhash:8].js',
    chunkFilename: 'js/[name].[chunkhash:8].js',
    publicPath: '/',
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/i,
        use: [
          'babel-loader',
        ],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({ // 根据模板插入css/js等生成最终HTML
      filename: './index.html', // 生成的html存放路径,相对于 path
      template: './public/index.html', // html模板路径
      hash: true, // 为静态资源生成hash值
      minify: { // 压缩HTML文件
        removeComments: true, // 移除HTML中的注释
        collapseWhitespace: true, // 删除空白符与换行符
      },
    }),
  ],
  optimization: {
    splitChunks: {
      chunks: 'all',
      maxInitialRequests: Infinity,
      minSize: 8000,
      cacheGroups: {
        common: {
          test: /[\\/]src[\\/](utils|components)/,
          name: 'common', // todo: 区分 component / utils
        },
      },
    },
  },
}

pdf.js

const ap = () => {
  console.log('test async')
}

const aa = async () => {
  await ap()
}

aa()

package.json

{}

remark

"webpack": "^5.1.0",
"@babel/runtime-corejs3": "^7.14.7",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.14.7",

Answer №1

.babelrc configuration files have an impact solely on the files within the particular package where the config is located, leaving sub-packages untouched. To ensure all packages are affected, utilize a babel.config.js file. For more information, visit: https://babeljs.io/docs/en/config-files#project-wide-configuration

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

Verify if uploading a photo is necessary

Here is my approach to ensuring that a file is added before it can be uploaded: <script type="text/javascript> function check(){ var elm = document.getElementById("hello-world"); if (elm.value.length > 0){ alert("Hey"); re ...

Why is inner HTML returning input/textbox instead of the value?

I need help extracting the value from an input/textbox within a table cell. Although the rest of my code is functioning correctly, I'm struggling to retrieve the value from this particular input element. I've attempted to access the value using ...

Is it possible to combine asynchronous and synchronous functions in the same code?

I've recently started experimenting with Node.js and I'm running into issues with asynchronous functions. While I was able to create a small game, the only way I could successfully integrate asynchronous functions with synchronous functions was b ...

Tips on displaying a spinner only when data is retrieved from an Http service

How can I ensure that a spinner is only shown during an HTTP service call and dismissed when my component receives data? To address this issue, I implemented a cache service to store data fetched from the HTTP service for future use. However, I want to sh ...

Exploring the nuances of various browsers in JavaScript

I am facing an issue where my JavaScript code functions correctly in Internet Explorer, but not in Firefox or Safari. I have a loop that goes through each element and, depending on the variable inside a text box, triggers an alert message. The code snippet ...

Altering the status of a property in an object, at a specific position within a collection of objects, contained within another object?

Currently using React and having some trouble with the setState hook to update a value deep within an object structure ...

Enable automatic importing for my React library in vscode

I am currently in the process of developing a library of components specifically for React, with the intention of publishing it on npm. To achieve this, I am using webpack and babel to compile the code to ES5. Most of the setup has been successful, howeve ...

Seeking the Bluebird promise method "any" within a sequence

One of my requirements involves running Promise.any in series. Since Promise.any is not available (correct me if I'm wrong), I created a function to execute promises sequentially using Pomise.mapSeries and resolve at the first satisfied test. The pr ...

submit data entered in text fields using a php form

I have set up a form using Ninja Forms on my WordPress site. The form is lengthy and divided into tabs. When a user clicks the first button to proceed, I intend to send an email containing specific fields. However, I am facing an issue where the variables ...

Deactivate the button in the final <td> of a table generated using a loop

I have three different components [Button, AppTable, Contact]. The button component is called with a v-for loop to iterate through other items. I am trying to disable the button within the last item when there is only one generated. Below is the code for ...

Display or conceal <tr> elements according to various <select> boxes using angularjs

My current setup includes a multiple select box as shown below <select multiple name="transActionGroup" id="transActionGroup" ng-multiple="true" ng-model="transActionGroup" title="Hold CTRL to select more than one transaction type."> <option ...

The hierarchy of precedence when using the TypeScript Type Assertion operator

Is it necessary to wrap the js-ternary operator with 'as' Type Assertion? ios ? TouchableOpacity : View as React.ElementType Will it automatically use the result of '?:' since it comes first? Or would a better implementation be: (ios ...

Automatically hide a label after a certain amount of time following a button click

Currently, I am working with ASP.NET and C#. Within my application, there is a registration form that includes a label to display the status of registration, either success or failure. The content of this label is determined dynamically in the codebehind ...

Inquiries about ngshow and the scope concept

I have a question about using AngularJS. I have multiple sections and only want to display one at a time using <section ng-show="section6_us"> </section> and <section ng-show="section7_us"> </section>. My scope has many variables. ...

setTimeout does not include the function showBox

Whenever I use console.log(this.showBox) inside the setTimeout() function, it unexpectedly returns undefined instead of false. Could someone please explain if the setTimeout() affects the accessibility of this.keyword? Thank you! <script> import Bl ...

Having difficulty in dynamically loading an image from an API's URL in Angular

In the title, I mentioned that I am utilizing a free API to display cryptocurrency news for my practice project. Everything seems to be working fine except for displaying the images in card view. I will share my code here, so if you have any suggestions on ...

I have a Dart Function that needs to be converted to work with Vue.js axios.post() functionality

Here is a Dart function for uploading a selected image to a Node server. I want to implement this functionality using Vue.js. var stream = new http.ByteStream(DelegatingStream.typed(file.openRead())); var length = await file.length(); var uri = ...

What is the best way to interact with the crontab file using Node.js?

Currently working on an Electron application, I am in need of accessing and parsing the crontab file. Is there a way for Node.js (or another tool within Electron) to retrieve and read the primary crontab file? While exploring the cron-parser library, I d ...

Passing methods from child to parent components in Vue2 looped componentsHere is a

Currently, I am iterating through the root component, which contains a child component within it. <root-select v-for="offer in offers" > <child-options v-for="item in options" > </child-options> </root-select> However, when ...

Import failures in Three.js could be attributed to potential issues with Webpack

Please note: I am utilizing create-react-app along with three.js v0.99.0. In my current project, I am faced with the challenge of importing specific modules from three.js to avoid bundling the entire library, which results in a large uncompressed file siz ...