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

Conflicting versions of ajv break the build #1433

Closed
BurkovBA opened this issue Aug 27, 2019 · 2 comments
Closed

Conflicting versions of ajv break the build #1433

BurkovBA opened this issue Aug 27, 2019 · 2 comments
Labels

Comments

@BurkovBA
Copy link

Description

My project depends on both react-jsonschema-form (which depends on ajv version 5) and a separate instance of ajv library, version 6.

When I build my project with Webpack, react-jsonschema-form is trying to use the global ajv version 6 instead of its own ajv version 5, resulting in an error in runtime:

Uncaught Error: schema should be object or boolean
    at Ajv._addSchema (ajv.js:303)
    at Ajv.addSchema (ajv.js:141)
    at Ajv.addMetaSchema (ajv.js:156)
    at addDraft6MetaSchema (ajv.js:454)
    at new Ajv (ajv.js:75)
    at createAjvInstance (validate.js:38)
    at Object.<anonymous> (validate.js:33)
    at __webpack_require__ (bootstrap 5b418ac9dcd29920a85c:678)
    at fn (bootstrap 5b418ac9dcd29920a85c:88)
    at Object.<anonymous> (utils.js:83)

Here is my code example:

index.jsx

import React from 'react';
import { withRouter } from 'react-router-dom';
import Form from "react-jsonschema-form";

import routes from 'services/routes.jsx';


class Index extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      schema: {
        title: "Todo",
        type: "object",
        required: ["title"],
        properties: {
          title: {type: "string", title: "Title", default: "A new task"},
          done: {type: "boolean", title: "Done?", default: false}
        }
      }
    };
  }

  render() {
    return (
      <div className="row">
        <div className="col-lg-12">
          <div className="hpanel">
            <div className="panel-heading">
              <h1>Ожидаемая эффективность клиентских менеджеров</h1>
            </div>
            <div className="panel-body">
              <Form schema={this.state.schema} onChange={console.log("changed")} onSubmit={console.log("submitted")} onError={console.log("errors")} />
            </div>
          </div>
        </div>
      </div>
    )
  }
}

export default withRouter(Index);

Problem can be solved by importing your bundle from /dist folder instead of using main module:

import Form from "react-jsonschema-form/dist/react-jsonschema-form.js";

instead of

import Form from react-jsonschema-form

Version

Encountered in react-jsonschema-form 1.7 and 1.8.

@epicfaace
Copy link
Member

Thanks for reporting. #1286 would probably fix this.

@stale
Copy link

stale bot commented Apr 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Apr 15, 2022
@stale stale bot closed this as completed May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants