question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

not able to transform arrow functions while bundling js

See original GitHub issue

Bug report

What is the current behavior? I can see a new feature called dependOn is added to webpack which fits in rightly for my requirement. As I moved my webpack version from 4.43.0 to 5.0.0-beta.16, for some reasons the transformation of arrow function in bundle.js is not happening.

If the current behavior is a bug, please provide the steps to reproduce. Let me share my configurations.

Package.json

`

{
  "name": "root",
  "private": true,
  "workspaces": [
    "compositions/*"
  ],
  "dependencies": {
    "classnames": "^2.2.6",
    "core-js": "3",
    "react": "^16.10.2",
    "react-dom": "^16.10.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.6",
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/plugin-transform-runtime": "^7.9.6",
    "@babel/polyfill": "^7.8.7",
    "@babel/preset-env": "^7.9.6",
    "@babel/preset-react": "^7.9.4",
    "@emcm-ui/stylelint-config": "^1.2.2",
    "@storybook/react": "^5.3.18",
    "babel-core": "7.0.0-bridge.0",
    "babel-loader": "^8.1.0",
    "babel-plugin-styled-components": "^1.10.7",
    "babel-polyfill": "^6.26.0",
    "compression-webpack-plugin": "^3.1.0",
    "css-loader": "^3.5.3",
    "duplicate-package-checker-webpack-plugin": "^3.0.0",
    "es6-promise": "^4.2.8",
    "eslint": "^6.8.0",
    "fs-extra": "^9.0.0",
    "isomorphic-fetch": "^2.2.1",
    "lerna": "^3.20.2",
    "mini-css-extract-plugin": "^0.9.0",
    "module": "^1.2.5",
    "npm-run-all": "^4.1.5",
    "postcss": "^7.0.27",
    "postcss-calc": "^7.0.2",
    "postcss-css-variables": "^0.17.0",
    "prettier": "^1.19.1",
    "reduce-css-calc": "^2.1.7",
    "regenerator-runtime": "^0.13.5",
    "style-loader": "^1.2.1",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "webpack": "5.0.0-beta.16",
    "webpack-bundle-analyzer": "^3.6.0",
    "webpack-cli": "^3.3.11"
  },
  "scripts": {
    "build": "yarn format && webpack --mode production",
    "start": "start-storybook -p 5555",
    "npmScript": "webpack --mode production",
    "postcss": "node scripts/buildVars.js",
    "cleanup": "./cleanup.sh",
    "format": "yarn internal:prettier \"./*.{js,jsx,json,md}\" \"./**/*.{js,jsx,json,md}\" --write",
    "internal:lint:js": "eslint --ext .js,.jsx --ignore-path .eslintignore",
    "internal:prettier": "prettier",
    "lint": "npm-run-all lint:*",
    "lint:format": "yarn internal:prettier --list-different \"./*.{js,jsx,json,md}\" \"./**/*.{js,jsx,json,md}\"",
    "lint:js": "yarn internal:lint:js .",
    "lint:js:fix": "yarn internal:lint:js . --fix"
  }
}

`

webpack.config.js

`

const path = require("path");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
  .BundleAnalyzerPlugin;
const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack-plugin");
const webpack = require("webpack");
const getPackages = require("./scripts/getPackages");
const localPackage = require("./package.json");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = {
  entry: {
    icons: path.resolve(__dirname, "node_modules", "@emcm-ui/icons")
  },
  output: {
    filename: "[name].js"
  },
  devServer: {
    inline: true,
    port: 3002
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              [
                "@babel/preset-env",
                {
                  useBuiltIns: "entry",
                  corejs: { version: 3, proposals: true }
                }
              ],
              "@babel/preset-react"
            ],
            plugins: [
              "@babel/plugin-proposal-class-properties",
              "@babel/plugin-transform-arrow-functions",
              "@babel/plugin-transform-runtime"
            ]
          }
        }
      },
      {
        test: /\.css$/,
        use: [
          // This is executed in reverse order #important
          MiniCssExtractPlugin.loader,
          // "style-loader",
          "css-loader" // this is used to understand the import statement in js for css
        ]
      }
    ]
  },
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: "static",
      generateStatsFile: true,
      openAnalyzer: false,
      statsOptions: {
        source: false
      }
    }),
    new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: "[name].css"
    }),
    new DuplicatePackageCheckerPlugin()
  ]
};
`

**polyfill.js**

`
import "regenerator-runtime/runtime";
import "core-js/es";
import "isomorphic-fetch";
import es6Promise from "es6-promise";

es6Promise.polyfill();

`

What is the expected behavior? I should see my bundle.js transformed into without arrow function in them as most of the browsers cannot read them. The same works when I downgrade my webpack version to 4.43.0

Other relevant information: webpack version: 5.0.0-beta.16 Node.js version: v12.16.2 Operating System: Windows 32 Additional tools: VSCode

Any help would be appreciated

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vankopcommented, May 7, 2020

@anooj-curator probably you need to decrease ecmaVersion, take a look https://github.com/webpack/changelog-v5#improved-code-generation

0reactions
branchardcommented, May 14, 2020

Putting output.ecmaVersion: 2009 seems to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bundle.js still contains arrow function and default parameters ...
I am using webpack 5, and setting target to es5 in webpack.config.js solved the problem for me. module.exports = { target: 'es5', ......
Read more >
Webpack 5 Beta + babel-loader: Why do I still have arrow ...
Cue my surprise when popping open bundles only to discover that some fat arrows were still, um, arrows. I dug through the v4...
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >
A Guide to Managing Webpack Dependencies - Toptal
A Guide to Managing Webpack Dependencies ... The Webpack module bundler processes JavaScript code and all static assets, such as stylesheets, images, and...
Read more >
Output - webpack
webpack will not write output file when file already exists on disk with the ... but you are still allowed to use something...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found