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:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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