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

Error is thrown when there's a warning in a file that is transformed into a bigger file #4920

Closed
abdulsattar opened this issue Mar 23, 2023 · 3 comments · Fixed by #4922
Closed
Assignees

Comments

@abdulsattar
Copy link

Rollup Version

3.18.0

Operating System (or Browser)

macOS Ventura

Node Version (if applicable)

No response

Link To Reproduction

https://stackblitz.com/edit/rollup-repro-wmdqgq?file=rollup.config.js,dist%2Fmain.js,src%2Fmain.js,package.json

Expected Behaviour

Working in 3.17.3: https://stackblitz.com/edit/rollup-repro-eeubaz?file=rollup.config.js,dist%2Fmain.js,src%2Fmain.js,package.json

Just warns about the missing export, but successfully completes compilation.

Actual Behaviour

Broken repro: https://stackblitz.com/edit/rollup-repro-wmdqgq?file=rollup.config.js,dist%2Fmain.js,src%2Fmain.js,package.json

Throws this error:

TypeError: Cannot read properties of undefined (reading 'slice')
    at getCodeFrame (file:///home/projects/rollup-repro-wmdqgq/node_modules/rollup/dist/shared/rollup.js:150:65)
    at augmentCodeLocation (file:///home/projects/rollup-repro-wmdqgq/node_modules/rollup/dist/shared/rollup.js:288:28)
    at Module.addLocationToLogProps (file:///home/projects/rollup-repro-wmdqgq/node_modules/rollup/dist/shared/rollup.js:14193:13)
    at Module.warn (file:///home/projects/rollup-repro-wmdqgq/node_modules/rollup/dist/shared/rollup.js:14075:14)
    at resolveNamespaceVariables (file:///home/projects/rollup-repro-wmdqgq/node_modules/rollup/dist/shared/rollup.js:9876:24)

My understanding, when I debugged this, is it's trying to get the line number in the original source code, not in the transformed source code (sourcemaps don't exist) and it's throwing this error.

@lukastaegert
Copy link
Member

Fix at #4922. The problem is that your plugin changes lines in a file without generating a sourcemap. This is a problem in so far as warnings and errors will report wrong locations. You should ideally use something like magic-string to generate a source map for your changes.
The fix will not fix the warning location but prevent the crash.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4922 as part of rollup@3.20.2. You can test it via npm install rollup.

@abdulsattar
Copy link
Author

Thank you for the quick fix @lukastaegert!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants