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

Cannot read property 'children' of undefined #137

Closed
Andorbal opened this issue Dec 6, 2016 · 2 comments
Closed

Cannot read property 'children' of undefined #137

Andorbal opened this issue Dec 6, 2016 · 2 comments
Labels

Comments

@Andorbal
Copy link

Andorbal commented Dec 6, 2016

I'm getting this error when building a simple app that has a component with a child named 'Link'. I'll have a super simple example below, but it looks like what's happening is that since link is a valid html element that expects no children, the parser is assuming my Link component is that and trying to set a child when none is expected.

If I change Link to anything else (Widget, Link2, etc.) everything works fine. I'd certainly prefer to name my component anything I'd like, so long as it starts with a capital letter and have everything just work. If we want to treat html elements as reserved words, then I think a better error would be really helpful since it took quite awhile to figure that out!

Link.html

<p>{{yield}}</p>

Main.html

<Link>Hello</Link

<script>
import Link from 'Link';

export default {
  components: {
    Link,
  }
};
</script>

Stack trace of the error:

Error transforming /home/andrew/learning/svelte/router/src/App.html with 'svelte' plugin: Cannot read property 'children' of undefined
TypeError: Error transforming /home/andrew/learning/svelte/router/src/App.html with 'svelte' plugin: Cannot read property 'children' of undefined
    at text (/home/andrew/learning/svelte/router/node_modules/svelte/compiler/parse/state/text.js:10:18)
    at parse (/home/andrew/learning/svelte/router/node_modules/svelte/compiler/parse/index.js:120:11)
    at Object.compile (/home/andrew/learning/svelte/router/node_modules/svelte/compiler/index.js:6:17)
    at Object.transform (/home/andrew/learning/svelte/router/node_modules/rollup-plugin-svelte/dist/rollup-plugin-svelte.cjs.js:24:18)
    at /home/andrew/learning/svelte/router/node_modules/rollup/src/utils/transform.js:19:35
    at process._tickCallback (internal/process/next_tick.js:103:7)

I did create a test with this that fails, but as I said above, I'm not sure if this is a bug or expected behavior.

Thanks, and I'm really digging this project so far!

@Rich-Harris
Copy link
Member

I'm not sure if this is a bug or expected behavior.

Good question! It's certainly surprising behaviour. Easy fix is to require void element names to be lowercase, which would fail with some valid HTML but I'm not sure if that's a real problem or not. #138

Rich-Harris added a commit that referenced this issue Dec 7, 2016
require void elements to be lowercase
@Rich-Harris
Copy link
Member

Fixed in 1.1.3

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

No branches or pull requests

2 participants