Skip to content

vite:dep-scan transformations can cause syntax errors confusingly reported by esbuild #2528

@tjk

Description

@tjk

For example, if you write the code (notice await in a comment):

// something something await
watch(() => result.data.value, data => {
}, { immediate: true })

The code here:

if (js.includes('await')) {
js = js.replace(/\bawait\s/g, 'void ')
}

will produce the following code to get sent to esbuild:

// something something void       watch(() => result.data.value, data => {
}, { immediate: true })

User will just see this error:

 > /component.vue:53:9: error: Expected identifier but found "{"
    53 │       }, { immediate: true })
       ╵          ^

error during build:
Error: Build failed with 1 error:
html:/component.vue:53:9: error: Expected identifier but found "{"

Does a proper parse need to happen to not secretly cause these issues or would a naive 'in comment' or 'in string' heuristic be good enough? At the very least it would maybe be nice to see what the code esbuild errored on but that seems non-trivial given it is just provided entries and then communicates back progress asynchronously?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions