Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal rollup crash when transform generates invalid js #13571

Closed
7 tasks done
manucorporat opened this issue Jun 20, 2023 · 4 comments · Fixed by rollup/rollup#5045 or #13608
Closed
7 tasks done

Internal rollup crash when transform generates invalid js #13571

manucorporat opened this issue Jun 20, 2023 · 4 comments · Fixed by rollup/rollup#5045 or #13608

Comments

@manucorporat
Copy link
Contributor

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

@stackblitz
Copy link

stackblitz bot commented Jun 20, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Jun 21, 2023

Should this be reported to Rollup instead? The code where it errors is at https://github.com/rollup/rollup/blob/833314c1621420e031340c1894e7863e062f7761/src/utils/error.ts#L50

@manucorporat
Copy link
Contributor Author

manucorporat commented Jun 21, 2023

Rollup has a problematic code path, but the root of the problem is somehow vite now allowing rollup to get the updated currentSource across transforms, so the error is augmented incorrectly.

I cant reproduce this issue only with rollup.

@manucorporat
Copy link
Contributor Author

The fix in rollup:
rollup/rollup#5045

would prevent the crash, but it would silence completely the error augmentation

@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants