Svelte - Unexpected token (parse-error)
It seems like Parcel fails to parse this in a Svelte popup:
because of the
as const
part
Plsamo version: 0.60.3-lab.2
79 Replies
After removing it, it seems like this is an invalid syntax:
Removing
.plasmo/
doesn't solve the issue eitherTry verbose logging and see if it spits out any other info :d
I did try, that's how I found out that the aforementioned lines were problematic
At the bottom of the code pasting, is there a stack trace?
Only the problematic line
what happens if you move that component outside of popup directory?
Move the file and remove the references to it, or just move?
you prob need to replace the reference too yeah - tho in my project when I move files around they automatically replace the path for me
My WebStorm also did it, but the error is the same
I'm not entirely sure yeah, this is the TS in svelte territory, this error comes from the TS checker within Svelte
I mean visually there aren't issues
š“ ERROR | Unexpected token (parse-error)Also this error could indicates hidden token btw afaik, this happens when you have a whitespace character somewhere that messed up the whole file
Maybe it has to do with the
tsconfig.json
How should it look like?It looks like this on the example:
Why both
.tsx
and .svelte
?oh true
yeah we can remove
.tsx
for this and vue as well xD good catchLmao
Also, IMO when a user does
similar to other CLIs like Vue/VIte, it should ask the user whether to start off from a vanilla boilerplate, Svelte, Vue, React and whether to add BGSW
Because I often forget the
--with-svelte
flag and I find myself doing
Annoyingly, --with-svelte
does produce a build that compiles even when doing const keys = new Set<string>()
hehhhh
interesting... good idea, I will add it in a future version - can you file an RFC issue? Also, if you're down to spearhead it pls do :p
My mind isn't quite free to work on projects that aren't mine ATM, plus I'll need some assistance anyway
aight logged in an rfc: https://github.com/PlasmoHQ/plasmo/issues/354
GitHub
[RFC] plasmo init prompt for template Ā· Issue #354 Ā· PlasmoHQ/plasmo
How do you envision this feature/change to look/work like? Also, IMO when a user does pnpx plasmo init extension-name similar to other CLIs like Vue/VIte, it should ask the user whether to start of...
I like how you basically copied my message into the issue
yeah lol xD
eventually I will add a feature into Pallas
where I can mention her to turn a message into a gh issue
It sounds like it should work, but the issue will not have enough info
The idea in my mind is that
it just need to log the data
and then reference the conversion ID on discord just like the issue above
then the people can continuing discussing it on Discord
the github issue is really to tracking, it can be used for discussing as needed
for me, the issue is used to create a branch
I'm curious how that'll work out
Interesting
I copied the files from the original Plasmo port into the test Svelte project, and after a few PNPM installs the error came back
it could be that the stack trace is wrong, or that there's a hidden character in that file
@louis Interesting, WebStorm randomly decided to throw the error mentioned by the Svelte compiler
The solution was:
but then, I get errors of
Unresolved type: KeyboardEvent
, so the total solution is
hmm interesting
all of that is included in the base plasmo tsconfig so not sure why that's needed ;d
GitHub
plasmo/tsconfig.base.json at 6342d64ad5e6208f9db3cae4cd46006104036c...
š§© The Browser Extension Framework. Contribute to PlasmoHQ/plasmo development by creating an account on GitHub.
Maybe it's not capitalized properly?
Why dafuq
I removed the
"lib"
line, re-ran pnpm dev
, and the error doesn't spit anymore
What is up...What the actual fuck
For some stupid reason, if I copy the Svelte snippet (https://github.com/PlasmoHQ/examples/blob/de42aa8fe74e2b025fa582112d59795c7c04ba4e/with-svelte/popup.svelte) over to this project, add
let set = new Set<string>();
and them remove everything else, it's fine
But if I start from the previous code, remove everything else until I'm left with let set = new Set<string>();
, it spits an error I wonder if this is because the default popup.svelte contains everything needed for svelte so the compiler doesn't throw, and since it has that cached even if you remove everything it would still be fine (?). I bet if you shutdown the dev server then try adding it back again, it will likely barf ;d
Restarting the dev server throws the same error š¤·āāļø
yup
That's one of the strangest issues I've encountered
does it work if you just do
let something = new Set<string>();
I mean it's literally the same piece of code
I've a suspicion that
set
and get
might be parsed as reserved keywordsNope
if you remove the template type annotation does it work?
It does
If you'd like I can screenshare
BTW
if you change
type="ts"
to lang="ts"
does it work?It does, maybe that was the issue?
lol yeah
Holy cow, a stupid typo ruined my past 4 months
dw we all been there
I think it's worth specifying it in a repo somewhere, to replace
type="ts"
with lang="ts"
all the svelte example uses
lang="ts"
, but yeah we can add it to the FAQ section in the svelte exampleOr, we can ignore it in the transformer level
well you would need to send a PR to the svelte preprocessor itself
No I mean, in Plasmo itself
(it's what looking at the code and figure out if it's ts/js)
you may try but what's the use of
type="ts"
? type is supposed to denote styling vs template or some other thing right
I don't think it's meant to use the way you were using anywayI.e. before sending the file to the processor, have
I mean that's the way I set up my Svelte files in my extensions so far
Is it better to inform the devs in a README about supporting
lang="ts"
or is it better to just let them run type="ts"
and take care of this mistake?Is
type="ts"
a standard within svelte?I dunno, but it works for me
I think it might work in like svelte 2.x or some
I looked up the docs, everywhere I look it all changed to
lang="ts"
I've always been using Svelte 3
Interesting
Like even the MDN docs: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/Svelte_TypeScript#porting_our_to-do_list_app_to_typescript
TypeScript support in Svelte - Learn web development | MDN
In this article we took our to-do list application and ported it to TypeScript.
^ I couldn't find that string lol
Wrap in double quotes
Yeah I think it's deprecated entirely - if you look at their docs, it's all
lang='ts'
only in that one image alt that I think they forgot to changeOk interesting, so the right solution might indeed be "make sure to have
lang="ts"
in your Svelte component"yeah
GitHub
doc: update
with-svelte
README (#27) Ā· PlasmoHQ/examples@aff8616Signed-off-by: avi12
Signed-off-by: avi12
Somehow
`lang="ts"
did not solve it in the following case:
Plasmo 0.64.2
popup.svelte
produces
hmmm is index a svelte file?
No,
index.d.ts
hmmm, try changing it to
index.ts
or include the .d - I don't think you can include declaration fileI renamed
index.d.ts
to types.ts
, but it spits the same errortry import it with
./types.ts
?
not sure how svelte is resolving import nowadayI did
Oh wait
Yeah, still
even after restarting the server?
Stopped the server, deleted
.plasmo/
, restarted the server, same error
Last time I got a proper description for (parse-error)
was via the browser, which was awkward
I deleted every Svelte file but popup.svelte
, changed that file's content to
still getting the error š¤·āāļølol what
lmao what
I
pnpx plasmo init proj --with-svelte
'd, copied over src/*
, and it magically works
I have no idea whether one or more deps were wrecked, but certainly nothing is wrong about any source filelol