Code Monkey home page Code Monkey logo

Comments (5)

handrews avatar handrews commented on June 5, 2024 1

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.

from json-schema-tools.

handrews avatar handrews commented on June 5, 2024

@ValYouW json-schema-ref-loader understands several formats. If there is a .json extension it will just try to parse it as JSON. I don't remember offhand what the default behavior is if the extension is unrecognized, but it's probably either YAML or JavaScript, both of which are more forgiving.

Given that you have module.exports, it looks like your file is probably JavaScript and not plain JSON.

from json-schema-tools.

ValYouW avatar ValYouW commented on June 5, 2024

@handrews Hi, I don't have "module.exports", I have a regular json file:

{
"a": 123,
"b": ""B"
...
}

As I wrote, I think that json-schema-ref-loader is working OK, converting the json to a module (here) but since WebPack works in a loader-chain fashion there is probably a loader that comes after json-schema-ref-loader that expects to get a json file but gets the json-schema-ref-loader output, which is a module... this is my assumptions, I am trying to see if I can "disable" all the loaders that comes after json-schema-ref-loader in the chain...

from json-schema-tools.

ValYouW avatar ValYouW commented on June 5, 2024

OK, found that in WebPack 4 changelog:

JSON
webpack now handles JSON natively
You may need to add type: "javascript/auto" when transforming JSON via loader to JS

So I need to "tell" webpack that json-schema-ref-loader emits javascript, so it will know that the json file is no longer a json and won't try to parse it (webpack 4 parse json files natively)... the problem is that I can't do it for "inline loaders"...

from json-schema-tools.

ValYouW avatar ValYouW commented on June 5, 2024

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 :)

from json-schema-tools.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.