Skip to content

Commit

Permalink
Use "react-server" convention to enforce that writer is only loaded i…
Browse files Browse the repository at this point in the history
…n a server
  • Loading branch information
sebmarkbage committed Dec 8, 2020
1 parent 265bc28 commit 9c3bfe2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/react-server-dom-webpack/npm/writer.js
Original file line number Diff line number Diff line change
@@ -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.'
);
10 changes: 8 additions & 2 deletions packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down
5 changes: 4 additions & 1 deletion packages/react-server-dom-webpack/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);

0 comments on commit 9c3bfe2

Please sign in to comment.