privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.56k stars 108 forks source link

Can't access lexical declaration 'value' before initialization #246

Closed wilkinson4 closed 2 years ago

wilkinson4 commented 2 years ago

Bug description

I am running into an issue while trying to convert our project from babel-loader to es-loader. I am getting the following error:

can't access lexical declaration 'value' before initialization

From the following code snippet:

import { TextField } from '@mui/material'
import { debounce } from 'lodash'
import { useCallback, useEffect, useState } from 'react'

const DebouncedTextField = ({
  value: valueProp,
  onChange: onChangeProp,
  wait = 500,
  ...props
}) => {
  const [value, setValue] = useState(value)

  useEffect(() => {
    setValue(valueProp)
  }, [valueProp])

  const onChangeDebounced = useCallback(debounce(onChangeProp, wait), [
    onChangeProp,
  ])

  const handleChange = (event) => {
    setValue(event.target.value)
    onChangeDebounced(event)
  }

  return <TextField {...props} value={value || ''} onChange={handleChange} />
}

export default DebouncedTextField

Reproduction

A simple example to use is via the following code snippet

const TaskDetailCardCollapsable = ({
  title,
  userOptions,
  taskId,
  isComplete,
  isMedRec,
  refresh,
  deps,
  allowedStatusChangeOptions,
}) => {
  const classes = useStyles({ taskStatus: task?.status })
  const [task, setTask] = useState({})
  ...

Where the issue here is task in const classes = useStyles({taskStatus: task?.status})

Node.js package manager

npm

Environment

System:
    OS: macOS 12.2.1
    CPU: (8) arm64 Apple M1
    Memory: 851.05 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.asdf/installs/nodejs/16.13.1/bin/node
    npm: 8.1.2 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    esbuild-loader: ^2.18.0 => 2.18.0
    webpack: ^5.70.0 => 5.70.0

Can you contribute a fix?

privatenumber commented 2 years ago

Thanks for the issue.

There isn't enough information for me to act on this though. Since this is a build-time plugin, the run-time code isn't sufficient in debugging.

Please provide a minimal reproduction so I can replicate the problem on my end. This will also help you prove that it's a bug in esbuild-loader, as opposed to your own code.

And in the future, when providing the error, please include the error stack because that shows the specifics of where it's coming from and provides insight into why.

Since this report is quite far fetched from being an esbuild-loader bug, I'm closing it until a minimal reproduction is provided. If you need help setting up, feel free to seek help in the Discussions tab.