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

Named import bug #258

Open
jimafisk opened this issue Jan 11, 2023 · 1 comment
Open

Named import bug #258

jimafisk opened this issue Jan 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jimafisk
Copy link
Member

There seems to be a bug when doing certain types of imports: Error: runtime error: index out of range [-1]

Full error
Please create a valid Plenti project or fix your app structure before trying to run this command again.
Error: runtime error: index out of range [-1] 

goroutine 22 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/plentico/plenti/cmd.Build.func1()
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build.go:70 +0xdd
panic({0x18af240, 0xc00040c450})
        /usr/local/go/src/runtime/panic.go:838 +0x207
github.com/plentico/plenti/cmd/build.compileSvelte(0x673?, 0x18e53ff?, {0xc0004b8060, 0x24}, {0xc0002ec000, 0x673}, {0xc0004b80f0, 0x2b}, {0xc00040c210, 0x15})
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build/compile.go:159 +0x19db
github.com/plentico/plenti/cmd/build.compileComponent({0x0?, 0x0?}, {0xc0004b8060, 0x24}, {0x200000003?, 0xc000589040?}, {0xc0004ca080?, 0xc00012b4b8?}, 0x84ee4a?, 0xc00000e108, ...)
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build/client.go:247 +0x485
github.com/plentico/plenti/cmd/build.Client.func3({0xc0004b8060, 0x24}, {0x2034c10, 0xc0003fc1a0}, {0x100?, 0xffffffffffffff9c?})
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build/client.go:182 +0x165
path/filepath.walk({0xc0004b8060, 0x24}, {0x2034c10, 0xc0003fc1a0}, 0xc00012b970)
        /usr/local/go/src/path/filepath/path.go:418 +0x123
path/filepath.walk({0xc00040c0d8, 0x15}, {0x2034c10, 0xc00019d1e0}, 0xc00012b970)
        /usr/local/go/src/path/filepath/path.go:442 +0x285
path/filepath.walk({0xc00046c3d0, 0xf}, {0x2034c10, 0xc0003fc340}, 0xc00012b970)
        /usr/local/go/src/path/filepath/path.go:442 +0x285
path/filepath.walk({0x18e6c2e, 0x7}, {0x2034c10, 0xc0003fc270}, 0xc00012b970)
        /usr/local/go/src/path/filepath/path.go:442 +0x285
path/filepath.Walk({0x18e6c2e, 0x7}, 0xc00012b970)
        /usr/local/go/src/path/filepath/path.go:505 +0x6c
github.com/plentico/plenti/cmd/build.Client({0xc0004ca080, 0x6}, {0x0?})
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build/client.go:174 +0x905
github.com/plentico/plenti/cmd.Build()
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/build.go:145 +0x979
github.com/plentico/plenti/cmd/serve.(*watcher).watch.func1()
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/serve/watcher.go:105 +0x1f3
created by github.com/plentico/plenti/cmd/serve.(*watcher).watch
        /home/jimafisk/Projects/jantcu/plentico/plenti/cmd/serve/watcher.go:86 +0x48c

@hlanderdev and I are still trying to pinpoint exactly what is causing this. One theory is that if you use the same named import (stores seem ok still) in both a child and parent component, you hit this error.

Notes:

  • The "out of index" seems to be thrown on
    layoutRootPath = strings.TrimSuffix(layoutRootPath, layoutParts[len(layoutParts)-2]+"/")
  • reStaticImport.FindAllString(ssrStr, -1) might be capturing too much
@jimafisk jimafisk added the bug Something isn't working label Jan 11, 2023
@jimafisk
Copy link
Member Author

This seems to be caused when there are too many imports in a row that require going back up directories, for example:

import Something from '../../path/to/something.svelte';
import SomethingElse from '../../../something_else.svelte';

The regex grabs more than the import so a weird hack that you can use as a temporary fix is putting a comment like this at the bottom of your template:

<!-- /"; Fixed -->

Trying to resolve these imports manually using regex might be a losing battle. Future plan includes looking into ESBuild to do this for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant