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

Errors upon encountering schema.org markup #305

Closed
benmccann opened this issue Jan 29, 2021 · 5 comments · Fixed by #622
Closed

Errors upon encountering schema.org markup #305

benmccann opened this issue Jan 29, 2021 · 5 comments · Fixed by #622

Comments

@benmccann
Copy link
Member

benmccann commented Jan 29, 2021

Describe the bug

Google recommends using schema.org JSON-LD markup so that they can better understand your website, but svelte-preprocess barfs upon encountering it

Logs

The error was encountered at:

node_modules/svelte-preprocess/dist/autoProcess.js:36:77

// todo: maybe add a try-catch here looking for module-not-found errors

To Reproduce

Paste the example <script type="application/ld+json"> from https://developers.google.com/search/docs/guides/intro-structured-data into an app

Expected behavior

svelte-preprocess should proceed silently when encountering an unrecognized script type

Stack

Build Error: @snowpack/plugin-svelte
Error: Cannot find module './transformers/ld+json'
Require stack:
- node_modules/svelte-preprocess/dist/autoProcess.js
- c3-next/node_modules/svelte-preprocess/dist/index.js
- c3-next/svelte.config.js
- c3-next/@root
@benmccann
Copy link
Member Author

I found it can be worked around with the preserve option: https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#auto-preprocessing-options

@kaisermann
Copy link
Member

kaisermann commented Feb 3, 2021

Hmmmm, should the preserve property have default values such as ld+json? I don't see a case where we would want to parse a script with type application/ld+json

@benmccann
Copy link
Member Author

I think I'd probably just ignore unrecognized language types instead since it'd probably be hard to come up with a complete list of ones to whitelist

@kaisermann
Copy link
Member

@benmccann That makes total sense 😅 will do it soon.

@Antoine-lb
Copy link

I found it can be worked around with the preserve option: https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#auto-preprocessing-options

@benmccann 's answer is good (e.g. it compiles), but is probably not enough if you are trying to make a schema dynamically.

I found an article that really nailed the job for me so I just wanted to share:
https://navillus.dev/blog/json-ld-in-sveltekit

dummdidumm pushed a commit that referenced this issue Jun 12, 2024
closes #305
closes #312

Turns out the preserve option doesn't actually do anything useful anymore because it's now looking at lang and not type as it was originally. The original issues are already fixed without specifying preserve at all.
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

Successfully merging a pull request may close this issue.

3 participants