question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with inline import json-schema-ref-loader

See original GitHub issue

Hi,

I have an issue when importing json using json-schema-ref-loader, this is most likely NOT json-schema-ref-loader issue but will appreciate if anyone can see what I’m missing…

So my import is like import MySchema from '@cloudflare/json-schema-ref-loader!./my-schema.json';

And I get the following error when running webpack:

Module parse failed: Unexpected token m in JSON at position 0 while parsing near 'module.exports ...

I assumed this is because there is some other loader who tries to parse the json after json-schema-ref-loader loaded it, so I prefixed the loader with !! which should disable all configured loaders: import MySchema from '!!@cloudflare/json-schema-ref-loader!./my-schema.json'; But still no luck 😦

If I change the file extension from json -> jjj the following works: import MySchema from '@cloudflare/json-schema-ref-loader!./my-schema.jjj';

Any ideas how I can resolve this? Thx!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
handrewscommented, May 13, 2019

Oh, I see- it’s outputting JavaScript which is now a problem. One day it will be possible to do things in JS without stacking a bajillion constantly changing frameworks on top of each other. Maybe.

0reactions
ValYouWcommented, May 13, 2019

OK, so to close this issue, this is what I ended up with:

  1. I removed the “inline loader” style when importing the schema
  2. Renamed all schema files to end with .schema.json
  3. Defined the following module rule in my webpack config:
{
  test: /\.schema\.json$/,
  loader: '@cloudflare/json-schema-ref-loader',
  type: 'javascript/auto',
  exclude: /node_modules/
}

This way json-schema-ref-loader will only handle my schema files and webpack will keep handling regular json files…

Thx 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema $Ref Parser - API Dev Tools
JSON Schema $Ref Parser is a full JSON Reference and JSON Pointer implementation that crawls even the most complex JSON Schemas and gives...
Read more >
Structuring a complex schema — Understanding JSON ...
This chapter will present the tools available for reusing and structuring schemas as well as some practical examples that use those tools. Schema...
Read more >
Gatsby JSON loader not following refs - Stack Overflow
I need to dereference (swap out JSON References) when importing JSON or YAML files directly into Gatsby pages. Gatsby is pretty good at ......
Read more >
How to create your own auto-completion for JSON and YAML ...
In this article, I demonstrate how to create a JSON Schema, to provide ... for JSON and YAML files on VS Code with...
Read more >
JSON Schema Serializer and Deserializer
This document describes how to use JSON Schema with the Apache Kafka® Java client and ... how the built-in JSON Schema support works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found