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.

Getting "Cannot convert non-arrow function to a function expression" upon build

See original GitHub issue
  • Check if updating to the latest Preact version resolves the issue

Describe the bug I have a helper class which is used within a preact component, and its failing on build due to the mentioned error in the name

To Reproduce This is a class which I am importing to a component to use to help calculate certain stuff:

class DuplicateChecker {
  constructor() {
    this.iframe = this.createIframe();
  }

  hasDuplicates = async () => {
    const check = await this.isDuplicateFoundOnFirst();

    return check;
  }

isDuplicateFoundOnFirst = () => {
    // do some stuff here
  }

createIframe = () => {
 // do something here
}
}

export const duplicateChecker = new DuplicateChecker();

and this is the error i am receiving upon building the application as it runs on dev without any problems:

 Cannot convert non-arrow function to a function expression.
  14 |   }
  15 |
> 16 |   hasDuplicates = async () => {
     |                      ^
  17 |     const checkFirstPage = await this.isDuplicateFoundOnFirst();
  18 |

Expected behavior The app builds and compiles any code using babel without any issues.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
rschristiancommented, Dec 9, 2021

So I ran into this StackOverflow question which seems to match your question here, and I see you’ve provided your .babelrc.

I’m not entirely sure that the .babelrc pickup is working as intentioned at the moment, even a plain { "presets": ["preact-cli/babel"] } runs into this issue. AFAIK that should be fine, will need to look into that more.

Regardless, you’re adding a couple redundant plugins and you can add the ones you actually need through your preact config file:

preact.config.js

export default (config, env, helpers) => {
    const { rule } = helpers.getLoadersByName(config, 'babel')[0];
    const babelConfig = rule.options;

    babelConfig.plugins.push(
        '@quickbaseoss/babel-plugin-styled-components-css-namespace',
        'babel-plugin-styled-components'
    );
}
1reaction
devlukaszcommented, Dec 9, 2021

This seems to be working! Deleted my .babelrc and used @rschristian way of adding babel plugisn and it seems to be running fine, so there is an issue with .babelrc most likely @developit

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot convert non-arrow function to a function expression ...
Solved, here is the solution: Thanks to https://github.com/rschristian. The issue was within the .babelrc file, so i've deleted it and added ...
Read more >
Getting "Cannot convert non-arrow function to a ... - GitHub
Hi, I am creating a build for a React app, which was created via nx, but I am getting this error: Cannot convert...
Read more >
Cannot convert non-arrow function to a function expression ...
Coding example for the question Cannot convert non-arrow function to a function expression. React/Preact build fail-Reactjs.
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions cannot be used as constructors. Calling them with new throws a TypeError . They also don't have access to the new.target...
Read more >
Arrow functions vs Regular functions in JavaScript
When Not to Use Arrow Function: · 1.Object methods var cat = { · 2.Callback functions with dynamic context. Take a look at...
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