{"id":11432,"library":"node-jsx","title":"Node.js JSX Require Hook","description":"node-jsx is a module designed to enable transparent `require()` of JSX files directly within Node.js environments. Published over a decade ago, its primary function was to transpile JSX syntax on-the-fly using Facebook's jstransform (an early JSX processing tool) so that Node.js could execute `.jsx` files without a prior build step. The package, currently at version 0.13.3, has been officially superseded by modern build pipelines involving tools like Babel, Webpack, Vite, or TypeScript's built-in JSX transformation capabilities. Its last known update was in April 2015, indicating it is no longer maintained. Modern JavaScript and React development workflows universally rely on dedicated transpilers and bundlers for JSX processing, making `node-jsx` an obsolete solution incompatible with contemporary ecosystems.","status":"abandoned","version":"0.13.3","language":"javascript","source_language":"en","source_url":"https://github.com/petehunt/node-jsx","tags":["javascript"],"install":[{"cmd":"npm install node-jsx","lang":"bash","label":"npm"},{"cmd":"yarn add node-jsx","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-jsx","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and exposes its functionality directly via `require()`. There is no ES Module equivalent.","wrong":"import { install } from 'node-jsx';","symbol":"install","correct":"require('node-jsx').install();"},{"note":"While functional, chaining `.install()` directly on the `require()` call is the idiomatic usage shown in its documentation.","wrong":"const jsx = require('node-jsx'); jsx.install({ ... });","symbol":"installWithOptions","correct":"require('node-jsx').install({ extension: '.jsx', harmony: true });"}],"quickstart":{"code":"const path = require('path');\nconst fs = require('fs');\n\n// Install the node-jsx require hook\nrequire('node-jsx').install({ harmony: true });\n\n// Imagine a simple JSX component file at src/MyComponent.jsx\n// const React = require('react');\n// module.exports = function MyComponent({ name }) { return <div>Hello, {name}!</div>; };\n\n// This package is for JSX transpilation only, it does not include React itself.\n// Trying to require modern React or a JSX file directly will likely fail\n// due to incompatibilities and missing React runtime. This example demonstrates\n// the setup, but requires a legacy React setup to actually run JSX.\n\n// For demonstration, let's pretend a legacy React is available.\n// In a real modern scenario, this setup is completely obsolete.\n\nconsole.log('node-jsx require hook installed. This setup is highly deprecated.');\nconsole.log('Modern projects use Babel/TypeScript for JSX transpilation.');\n","lang":"javascript","description":"Demonstrates the deprecated method of installing `node-jsx` to enable on-the-fly JSX transpilation for `require()` calls in Node.js, highlighting its obsolescence."},"warnings":[{"fix":"Migrate to a modern build setup using Babel (with @babel/preset-react) or TypeScript (with 'jsx' compiler option) and a bundler like Webpack or Vite. For server-side rendering, pre-transpile components or use `@babel/register` (for older Babel) or `ts-node` (for TypeScript) with appropriate configurations.","message":"This package is officially deprecated and completely unmaintained since 2015. It is incompatible with modern React versions (>=0.14) and contemporary JavaScript/JSX syntax.","severity":"breaking","affected_versions":">=0.14.0"},{"fix":"See the general fix for deprecation: use modern transpilers that support current ECMAScript and JSX specifications.","message":"The `harmony: true` option mentioned in its README for ES6 transforms is severely outdated and will not correctly process modern ES6+ or JSX features (e.g., Fragments, Hooks, spread attributes).","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"If your project uses ES Modules, this package is fundamentally incompatible. Use modern build tools that natively support ES Modules and JSX transformation.","message":"This package exclusively supports CommonJS (`require()`) and cannot be used with ES Modules (`import`). Node.js projects using ES Modules will not be able to utilize this hook.","severity":"gotcha","affected_versions":"*"},{"fix":"Always pre-transpile JSX files to plain JavaScript using a build step before deploying to production. Runtime transpilation should only be considered for development environments, and even then, modern alternatives offer better performance and compatibility.","message":"Using `node-jsx` for on-the-fly transpilation in production Node.js applications will incur significant performance overhead, as every `require()` of a JSX file involves a parsing and transformation step.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade your JSX transpilation pipeline entirely. `node-jsx` is incompatible with modern React. Use Babel or TypeScript instead.","cause":"Attempting to use `node-jsx` with modern React versions (>=0.14) which changed internal module structures significantly.","error":"Error: Cannot find module 'react/lib/ReactContext'"},{"fix":"Ensure `require('node-jsx').install()` is executed *before* any `.jsx` files are `require()`d. However, this only applies to the severely outdated setup. For modern projects, this error means your build/transpilation step is misconfigured.","cause":"Node.js attempting to parse a `.jsx` file directly without the `node-jsx` hook being correctly installed or because the file type isn't registered for transpilation.","error":"SyntaxError: Unexpected token '<'"},{"fix":"Verify that `node-jsx` is correctly installed (`npm install node-jsx`). Ensure you are using `require('node-jsx').install()` and not `import` syntax.","cause":"The `require('node-jsx')` call did not return an object with an `install` method. This could be due to a faulty installation or an attempt to use `import` with a CommonJS-only package.","error":"TypeError: Cannot read properties of undefined (reading 'install')"}],"ecosystem":"npm"}