From d6a83215f36e0e2afb914742d4798ab24c273fb7 Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Sun, 7 May 2023 13:34:03 -0700 Subject: [PATCH] Add code to repro --- .../index.js | 5 +++ .../package.json | 4 ++ pages/index.tsx | 5 ++- server.js | 42 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 node_modules/imagine-i-were-a-real-npm-package/index.js create mode 100644 node_modules/imagine-i-were-a-real-npm-package/package.json create mode 100644 server.js diff --git a/node_modules/imagine-i-were-a-real-npm-package/index.js b/node_modules/imagine-i-were-a-real-npm-package/index.js new file mode 100644 index 0000000..9f22971 --- /dev/null +++ b/node_modules/imagine-i-were-a-real-npm-package/index.js @@ -0,0 +1,5 @@ +import { useState } from "react"; + +export function useCustomHook() { + return useState(); +} diff --git a/node_modules/imagine-i-were-a-real-npm-package/package.json b/node_modules/imagine-i-were-a-real-npm-package/package.json new file mode 100644 index 0000000..07aec65 --- /dev/null +++ b/node_modules/imagine-i-were-a-real-npm-package/package.json @@ -0,0 +1,4 @@ +{ + "type": "module", + "main": "index.js" +} diff --git a/pages/index.tsx b/pages/index.tsx index b19de6e..fbc58f1 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,7 @@ +import { useCustomHook } from "imagine-i-were-a-real-npm-package"; + /** Add your relevant code here for the issue to reproduce */ export default function Home() { - return null + let ref = useCustomHook(); + return null; } diff --git a/server.js b/server.js new file mode 100644 index 0000000..b4bd3e0 --- /dev/null +++ b/server.js @@ -0,0 +1,42 @@ +// copied wholesale from https://nextjs.org/docs/pages/building-your-application/configuring/custom-server + +const { createServer } = require('http'); +const { parse } = require('url'); +const next = require('next'); + +const dev = process.env.NODE_ENV !== 'production'; +const hostname = 'localhost'; +const port = 3000; +// when using middleware `hostname` and `port` must be provided below +const app = next({ dev, hostname, port }); +const handle = app.getRequestHandler(); + +app.prepare().then(() => { + createServer(async (req, res) => { + try { + // Be sure to pass `true` as the second argument to `url.parse`. + // This tells it to parse the query portion of the URL. + const parsedUrl = parse(req.url, true); + const { pathname, query } = parsedUrl; + + if (pathname === '/a') { + await app.render(req, res, '/a', query); + } else if (pathname === '/b') { + await app.render(req, res, '/b', query); + } else { + await handle(req, res, parsedUrl); + } + } catch (err) { + console.error('Error occurred handling', req.url, err); + res.statusCode = 500; + res.end('internal server error'); + } + }) + .once('error', (err) => { + console.error(err); + process.exit(1); + }) + .listen(port, () => { + console.log(`> Ready on http://${hostname}:${port}`); + }); +});