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.

please provide an example on how to import this module from create-react-app application.

right now if you start a new project:

  • create-react-app myproject
  • npm install nats.ws
  • import { connect } from “nats.ws”

it will generate an error:

./node_modules/nats.ws/nats.mjs 3499:17
Module parse failed: Unexpected token (3499:17)
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.
| 
| function defaultJsOptions(opts4) {
>   opts4 = opts4 ?? {};
|   return extend1({
|     apiPrefix: defaultPrefix,

thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
aricartcommented, Apr 28, 2021

to build the repo:

npm run setup #(only the first time)
npm run install
npm run build

See the docs: https://github.com/nats-io/nats.ws#contributing

1reaction
aricartcommented, Apr 28, 2021

@SunChero glad you were able to unblock yourself. Using the latest, I was able to do this:

import React, {Component} from 'react'
import {connect} from '../node_modules/nats.ws/lib/src/mod.js'
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.server = props.server;
    this.doConnect();
  }

  doConnect() {
    connect({servers: [this.server]})
      .then((nc) => {
        this.nc = nc;
        this.nc.jetstreamManager()
          .then((jsm) => {
            this.jsm = jsm;
            console.info(`connected jsm`);
            this.jsm.streams.add({name: "my", subjects: ["my.>"]})
              .then((info) => {
                console.info(info);
              })
          })
          .catch((err) => {
            console.error(`failed to connect to jetstream: ${err}`);
          })
      })
      .catch((err) => {
        console.error(`failed to connect: ${err}`);
      })
  }

  render() {
    return (
      <div className="App">
        <header className="App-header">
          Hello NATS.ws!!!
        </header>
      </div>
    );
  }
}

export default App;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example Projects - React
There are many example projects created by the React community. We're keeping this page focused on the ones that use React without third-party...
Read more >
React.js Examples
A nice collection of often useful examples done in React.js.
Read more >
React Tutorial - W3Schools
React allows us to create reusable UI components. Start learning React now ❯. Learning by Examples. Our "Show React" tool makes it easy...
Read more >
react examples - CodeSandbox
Learn how to use react by viewing and forking react example apps on CodeSandbox.
Read more >
The Best React Examples - freeCodeCamp
React Component Example ... Components are reusable in React.js. You can inject value into props as given below: function Welcome(props) { return ...
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