rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.3k stars 2.19k forks source link

Basic example in the docs not working #3295

Closed pathum-kalhan closed 1 year ago

pathum-kalhan commented 1 year ago

Prerequisites

What theme are you using?

core

Version

5.0.0-beta.14

Current Behavior

This is my code

import React from "react";
import validator from "@rjsf/validator-ajv8";
import Form from "@rjsf/core";

export default function Test() {
  const schema = {
    title: "Todo",
    type: "object",
    required: ["title"],
    properties: {
      title: { type: "string", title: "Title", default: "A new task" },
      done: { type: "boolean", title: "Done?", default: false }
    }
  };
// @ts-ignore
  const log = (type) => console.log.bind(console, type);

  return (
    <Form
    // @ts-ignore
      schema={schema}
      validator={validator}
      onChange={log("changed")}
      onSubmit={log("submitted")}
      onError={log("errors")}
    />
  );
}

When I tried to run this I am getting this error

[./node_modules/@rjsf/validator-ajv8/dist/validator-ajv8.esm.js 441:44
Module parse failed: Unexpected token (441:44)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| 
|   isValid(schema, formData, rootSchema) {
>     const rootSchemaId = rootSchema["$id"] ?? ROOT_SCHEMA_PREFIX;
| 
|     try {](url)

These are the versions I am using

 "@rjsf/core": "^5.0.0-beta.14",
    "@rjsf/utils": "^5.0.0-beta.14",

Also, I tried the same thing in the code sandbox https://codesandbox.io/s/wizardly-wilson-nunesg?file=/src/App.js:0-625 There I am getting this error Could not find module in path: 'ajv8' relative to '/node_modules/@rjsf/validator-ajv8/dist/validator-ajv8.esm.js'

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- OS:Ubuntu 22.04.1 LTS
- Node:v19.2.0
- npm:8.19.3

Anything else?

No response

heath-freenome commented 1 year ago

This is a duplicate of #3240, closing

nickgros commented 1 year ago

The error Could not find module in path: 'ajv8' relative to '/node_modules/@rjsf/validator-ajv8/dist/validator-ajv8.esm.js' is caused by a workaround that we used to fix our own module resolution issues in the playground. It's unclear if this is a CodeSandbox issue or if the issue can be encountered in other environments.