diff --git a/packages/react-server-dom-webpack/npm/writer.js b/packages/react-server-dom-webpack/npm/writer.js index f6c173050e057..13a632e641179 100644 --- a/packages/react-server-dom-webpack/npm/writer.js +++ b/packages/react-server-dom-webpack/npm/writer.js @@ -1,3 +1,6 @@ 'use strict'; -module.exports = require('./writer.node.server'); +throw new Error( + 'The React Server Writer cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.' +); diff --git a/packages/react-server-dom-webpack/package.json b/packages/react-server-dom-webpack/package.json index 478218e978403..711ffb37d68e8 100644 --- a/packages/react-server-dom-webpack/package.json +++ b/packages/react-server-dom-webpack/package.json @@ -25,9 +25,15 @@ "exports": { ".": "./index.js", "./plugin": "./plugin.js", - "./writer": "./writer.js", - "./writer.browser.server": "./writer.browser.server.js", + "./writer": { + "react-server": { + "node": "./writer.node.server.js", + "browser": "./writer.browser.server.js" + }, + "default": "./writer.js" + }, "./writer.node.server": "./writer.node.server.js", + "./writer.browser.server": "./writer.browser.server.js", "./node-loader": "./esm/react-server-dom-webpack-node-loader.js", "./node-register": "./node-register.js", "./package.json": "./package.json" diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js index 0eda8b6bd740f..a481d6ebbcd62 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js @@ -40,7 +40,7 @@ describe('ReactFlightDOM', () => { Stream = require('stream'); React = require('react'); ReactDOM = require('react-dom'); - ReactServerDOMWriter = require('react-server-dom-webpack/writer'); + ReactServerDOMWriter = require('react-server-dom-webpack/writer.node.server'); ReactServerDOMReader = require('react-server-dom-webpack'); }); diff --git a/packages/react-server-dom-webpack/writer.js b/packages/react-server-dom-webpack/writer.js index d541dad86c3c5..00db7f503faf7 100644 --- a/packages/react-server-dom-webpack/writer.js +++ b/packages/react-server-dom-webpack/writer.js @@ -7,4 +7,7 @@ * @flow */ -export * from './writer.node.server'; +throw new Error( + 'The React Server Writer cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.', +);