Sapper: 'level' is not defined error

Created on 6 Mar 2019  路  8Comments  路  Source: sveltejs/sapper

It looks like App.svelte generates level-Infinity when src/routes/index.html is not present.

bug

All 8 comments

Moving from sapper-template to sapper

It looks the issue occurs to me when I use the --ext extension.

Does anyone have a reproduction?

I can't reproduce this by deleting only src/routes/index.svelte, but I _can_ reproduce it by starting from the default template and deleting everything inside src/routes/.... Setting --ext foo also causes this, presumably because Sapper can't find any routes then either.

This is probably happening here as calling Math.max() with no arguments returns -Infinity. Since manifest_data.pages.map(page => page.parts.filter(Boolean).length) produces an empty array if there are no pages in the manifest.

This happens when there are no pages as far as I'm aware. While this is hardly exactly how we want to handle this case it looks more like an error that should be handled better rather than anything else.

If anyone has a reproduction of this that happens when there are pages present then please share it.

I found the issue (at least for me). It only happens in CMD (Windows CLI). It's not a problem with Sapper but rather with escaping on CMD I guess.

If you use --ext '.svelte .whatever', simple quote included, this will not work on windows, because the CLI arg will be '.svelte .whatever' with the quotes.

On CMD, the args given to the CLI are:

[ '--ext', '\'.svelte\'' ]

On Unix-based Shell:

[ '--ext', '.svelte' ]

So at the end Sapper uses '.svelte', giving it no files at all, giving the Infinity bug.
I don't use Windows at all and I wasn't aware about that. The problem only arose to my co-worker.

So basically, @btakita, try to use double-quotes if you are on Windows. If you aren't, it would be good if you could give a repro.

This issue was created before --ext existed, so it's not related to that.

I was not able to reproduce the issue as originally described, but I _was_ able to reproduce this behavior when there are no page routes at all. This is a bug but a very low priority one, for obvious reasons.

The stuff with --ext indicates that there is probably some more that ought to be documented here. We should make it clear that you need to enclose the space-separated extensions in quotes (or, I guess, escape the spaces with backslashes), and that on Windows you need to use double and not single quotes.

ran into this today with @pngwn. confirmed that changing my npm script to "start": "sapper dev --ext '.svexy .svelte'", works

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benmccann picture benmccann  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

Rich-Harris picture Rich-Harris  路  4Comments

BMorearty picture BMorearty  路  3Comments