Skip to content

Internal rollup crash when transform generates invalid js #13571

@manucorporat

Description

@manucorporat

Describe the bug

When a plugin incorrectly transform JS code into invalid JS code, instead of showing the actual parsing error. It makes rollup crash in the error augmentation code.

Seems like an bug shared between rollup and vite. The error augmentation code should use the sourceCode as the last transform. Not the original source code.

> vite build

vite v4.3.9 building for production...
✓ 3 modules transformed.
✓ built in 85ms
[vite:build-import-analysis] Cannot destructure property 'line' of 'locate(...)' as it is undefined.
file: /home/projects/vitejs-vite-5cun7m/counter.js
error during build:
TypeError: Cannot destructure property 'line' of 'locate(...)' as it is undefined.
    at augmentCodeLocation (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/rollup/dist/es/shared/node-entry.js:2250:17)
    at Object.error (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/rollup/dist/es/shared/node-entry.js:23856:25)
    at Object.transform (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:45130:22)
 ELIFECYCLE  Command failed with exit code 1.

Reproduction

https://stackblitz.com/edit/vitejs-vite-5cun7m?file=main.js,integrations.vscode.userData.settingsRaw,vite.config.js,counter.js,index.html&terminal=dev

Steps to reproduce

pnpm run build

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
  npmPackages:
    vite: ^4.3.9 => 4.3.9

Used Package Manager

npm

Logs

> vite build

vite v4.3.9 building for production...
✓ 3 modules transformed.
✓ built in 85ms
[vite:build-import-analysis] Cannot destructure property 'line' of 'locate(...)' as it is undefined.
file: /home/projects/vitejs-vite-5cun7m/counter.js
error during build:
TypeError: Cannot destructure property 'line' of 'locate(...)' as it is undefined.
    at augmentCodeLocation (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/rollup/dist/es/shared/node-entry.js:2250:17)
    at Object.error (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/rollup/dist/es/shared/node-entry.js:23856:25)
    at Object.transform (file://file:///home/projects/vitejs-vite-5cun7m/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:45130:22)
 ELIFECYCLE  Command failed with exit code 1.

Validations

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