I have this node js application:
require('babel-register');
const router = require("./src/web/router");
and I am getting this error:
how can I import react component in node js?
possible using esm node pacakge, esm is a fast, production ready, zero-dependency ES module loader for Node 6+.
If you are not interested in server side rendering your react component I made a small library that makes it easy to render react components from a node application https://github.com/tswayne/react-helper#getting-started. If you are trying to server side render, or import the react component for any other reason, you will need to compile your server side code with babel or use something like babel-node to compile at runtime.
.babelrcfile with the babel-preset-react added? If yes, please include it in your question. If not – that's the cause of the error.{ presets: ["react"] }npx create-react-appenter the newly reacted directory and runnpm startit will start example React application. Than you can move your existing code