-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSC: Use experimental node loader (#8979)
Use experimental node loaders when launching the RSC FE Server This is all done to try to make loading of 3rd party modules work. Specifically have been experimenting with the `server-only` package. In the end it turned out that it's not working because there's a bug/missing feature in Vite vitejs/vite#13487
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This loader is needed to make react-server-dom-webpack/node-loader work. | ||
// Without it we get the following error: | ||
// | ||
// resolve ./dist/node/index.js { | ||
// conditions: [ 'node', 'import', 'node-addons', 'react-server' ], | ||
// importAssertions: [Object: null prototype] {}, | ||
// parentURL: 'file:///Users/tobbe/tmp/rw-rsc-esm/node_modules/vite/index.cjs' | ||
// } | ||
// (node:33561) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getSource, transformSource | ||
// /Users/tobbe/tmp/rw-rsc-esm/node_modules/@redwoodjs/vite/dist/react-server-dom-webpack/node-loader.js:357 | ||
// throw new Error('Expected source to have been loaded into a string.'); | ||
// ^ | ||
|
||
// Error: Expected source to have been loaded into a string. | ||
// at load (/Users/tobbe/tmp/rw-rsc-esm/node_modules/@redwoodjs/vite/dist/react-server-dom-webpack/node-loader.js:357:13) | ||
// at async nextLoad (node:internal/modules/esm/loader:163:22) | ||
|
||
export async function load(url: string, context: any, nextLoad: any) { | ||
// console.log('waku-lib/node-loader: load', context.format, url) | ||
|
||
const result = await nextLoad(url, context, nextLoad) | ||
|
||
if (result.format === 'module') { | ||
let { source } = result | ||
|
||
if (typeof source !== 'string') { | ||
source = source.toString() | ||
} | ||
|
||
return { ...result, source } | ||
} | ||
|
||
return result | ||
} |