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

error importing parse #821

Closed
sibelius opened this issue Oct 23, 2023 · 3 comments
Closed

error importing parse #821

sibelius opened this issue Oct 23, 2023 · 3 comments

Comments

@sibelius
Copy link

Description

I'm following this nextjs guide

https://github.com/asyncapi/asyncapi-react/blob/master/docs/usage/nextjs.md#usage-with-ssrssg-static-documentation

and I can't import parse

export 'parse' (imported as 'parse') was not found in '@asyncapi/parser' (possible exports: AsyncAPIDocumentV2, AsyncAPIDocumentV3, BaseModel, BindingV2, BindingsV2, ChannelParameterV2, ChannelParametersV2, ChannelV2, ChannelsV2, Collection, ComponentsV2, ContactV2, CorrelationIdV2, DiagnosticSeverity, ExtensionV2, ExtensionsV2, ExternalDocumentationV2, InfoV2, LicenseV2, MessageExampleV2, MessageExamplesV2, MessageTraitV2, MessageTraitsV2, MessageV2, MessagesV2, OAuthFlowV2, OAuthFlowsV2, OldAsyncAPIDocument, OldBase, OldChannel, OldChannelParameter, OldComponents, OldContact, OldCorrelationId, OldExternalDocs, OldLicense, OldMessage, OldMessageTrait, OldOAuthFlow, OldOperation, OldOperationTrait, OldSchema, OldSecurityRequirement, OldSecurityScheme, OldServer, OldServerVariable, OldTag, OperationTraitV2, OperationTraitsV2, OperationV2, OperationsV2, Parser, SchemaV2, SchemasV2, SecuritySchemeV2, SecuritySchemesV2, ServerV2, ServerVariableV2, ServerVariablesV2, ServersV2, TagV2, TagsV2, convertToNewAPI, convertToOldAPI, createAsyncAPIDocument, default, fromFile, fromURL, isAsyncAPIDocument, isOldAsyncAPIDocument, stringify, toAsyncAPIDocument, unstringify)
TypeError: (0 , _asyncapi_parser__WEBPACK_IMPORTED_MODULE_4__.parse) is not a function
    at process (AsyncApi.tsx:9:1)
    at eval (AsyncApi.tsx:35:1)

Expected result

import { parse } from '@asyncapi/parser'

should work

Actual result

and I can't import parse

export 'parse' (imported as 'parse') was not found in '@asyncapi/parser' (possible exports: AsyncAPIDocumentV2, AsyncAPIDocumentV3, BaseModel, BindingV2, BindingsV2, ChannelParameterV2, ChannelParametersV2, ChannelV2, ChannelsV2, Collection, ComponentsV2, ContactV2, CorrelationIdV2, DiagnosticSeverity, ExtensionV2, ExtensionsV2, ExternalDocumentationV2, InfoV2, LicenseV2, MessageExampleV2, MessageExamplesV2, MessageTraitV2, MessageTraitsV2, MessageV2, MessagesV2, OAuthFlowV2, OAuthFlowsV2, OldAsyncAPIDocument, OldBase, OldChannel, OldChannelParameter, OldComponents, OldContact, OldCorrelationId, OldExternalDocs, OldLicense, OldMessage, OldMessageTrait, OldOAuthFlow, OldOperation, OldOperationTrait, OldSchema, OldSecurityRequirement, OldSecurityScheme, OldServer, OldServerVariable, OldTag, OperationTraitV2, OperationTraitsV2, OperationV2, OperationsV2, Parser, SchemaV2, SchemasV2, SecuritySchemeV2, SecuritySchemesV2, ServerV2, ServerVariableV2, ServerVariablesV2, ServersV2, TagV2, TagsV2, convertToNewAPI, convertToOldAPI, createAsyncAPIDocument, default, fromFile, fromURL, isAsyncAPIDocument, isOldAsyncAPIDocument, stringify, toAsyncAPIDocument, unstringify)
TypeError: (0 , _asyncapi_parser__WEBPACK_IMPORTED_MODULE_4__.parse) is not a function
    at process (AsyncApi.tsx:9:1)
    at eval (AsyncApi.tsx:35:1)

Steps to reproduce

try to use this on docusaurus

 "@asyncapi/parser": "^2.1.1",
    "@asyncapi/react-component": "^1.0.0-next.54",

it breaks on 1.0.3

Troubleshooting

@github-actions
Copy link

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

jonaslagoni commented Oct 24, 2023

Hey @sibelius, looks like the examples got overlooked when we updated the parser... I think the following should work, let me know!

import { Parser } from "@asyncapi/parser";
// import component without parser onboard
import { AsyncApiComponentWP } from "@asyncapi/react-component";

// Import styles
import "@asyncapi/react-component/styles/default.min.css";

export default function AsyncApiDocsPage({ asyncapi }) {
  const config = {}; // Configuration for component. This same as for normal React component
  return (
    <AsyncApiComponentWP schema={asyncapi} config={config} />
  )
}

// This function gets called at build time
export async function getStaticProps() {
  const schema = `...`; // AsyncAPI specification, fetched or pasted.

  // validate and parse
  const parser = new Parser();
  const {document, diagnostics} = await parser.parse(schema);
  // Circular references are not supported. See https://github.com/asyncapi/parser-js/issues/293
  const stringified = JSON.stringify(document.json());

  return {
    props: {
      asyncapi: stringified,
    },
  }
}

@sibelius
Copy link
Author

it works, tks

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

No branches or pull requests

2 participants