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 (Cannot read properties of undefined) is not referencing the correct line #707

Closed
1 task
panwauu opened this issue Jan 17, 2023 · 2 comments
Closed
1 task

Comments

@panwauu
Copy link

panwauu commented Jan 17, 2023

What version of astro are you using?

1.9.0

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

I noticed that the error overlay shows some errors on the wrong line if i try to access a property of an undefined variable. I noticed it with the new beta but it is also reproducible in 1.9.0. Below you can see the component with an error in line 7 and in the error the line 15 is referenced.
Hope this helps. I can not investigate as I dont even know which part of the pipeline/code generates the error (dont even know if it is an astro bug).

---
const test = undefined
---

<html>
	<main>
		<p>{test.variable}</p> // Error should be in this line
	</main>
</html>

<style>
	main {
		margin: auto;
		padding: 1.5rem;
		max-width: 60ch;
	}
</style>
 error   Cannot read properties of undefined (reading 'variable')
  File:
    /home/projects/github-tinlly/src/pages/index.astro:15:36
  Code:
    14 |     padding: 1.5rem;
    > 15 |     max-width: 60ch;
         |                                    ^
      16 |   }
      17 | </style>
  Stacktrace:
TypeError: Cannot read properties of undefined (reading 'variable')
    at eval (/home/projects/github-tinlly/src/pages/index.astro:15:36)
    at Module.renderPage (file://file:///home/projects/github-tinlly/node_modules/astro/dist/runtime/server/render/page.js:104:36)
    at Module.renderPage (file://file:///home/projects/github-tinlly/node_modules/astro/dist/core/render/core.js:103:51)
    at async Module.renderPage (file://file:///home/projects/github-tinlly/node_modules/astro/dist/core/render/dev/index.js:123:10)
    at async Module.handleRoute (file://file:///home/projects/github-tinlly/node_modules/astro/dist/vite-plugin-astro-server/route.js:168:20)
    at async run (file://file:///home/projects/github-tinlly/node_modules/astro/dist/vite-plugin-astro-server/request.js:62:14)
    at async Module.runWithErrorHandling (file://file:///home/projects/github-tinlly/node_modules/astro/dist/vite-plugin-astro-server/controller.js:83:5)
    at async Module.handleRequest (file://file:///home/projects/github-tinlly/node_modules/astro/dist/vite-plugin-astro-server/request.js:56:3)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-tinlly?file=src%2Fpages%2Findex.astro&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@Princesseuh
Copy link
Member

Thank you for creating this issue! I confirm that this is not fixed in 2.0.0, might be a sourcemap issue. Moving to the compiler repo

@Princesseuh Princesseuh transferred this issue from withastro/astro Jan 17, 2023
@natemoo-re
Copy link
Member

Going to merge this into #341

@natemoo-re natemoo-re closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants