You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to fetch data from a JSON file stored locally to populate inputs and selects in a form with NextJS. The server component of the page uses the useEffect to fetch the data with a helper function like so:
'use client'asyncfunctiongetOptionsData(){constfilePath=path.resolve(process.cwd(),'data.json');constfile=Bun.file(filePath);constcontents=file.json();returncontents;}exportdefaultfunctionHome(){
...
useEffect(()=>{getOptionsData().then((data)=>{setOptions(data);}).catch((err)=>{alert('Failed to fetch data: '+err);});},[]);
...
What is the expected behavior?
Be able to read a file locally as if it was being read from a script or using the fs module like so:
Running the script with bun run script.ts works like a charm.
What do you see instead?
Running the dev server with yarn run dev yields in the following error:
Returns the following error:
Failed to fetch data: ReferenceError: Bun is not defined
Then, attempting with bun --bun run dev I get this error which I believe has some relation with this #5363:
ConnectionClosed: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()
path: "http://localhost:54867/"
[0.02ms] ".env.local"
- error 29 | let ErrorType = Error;
30 | if (serializedErr.name === "PageNotFoundError") {
31 | ErrorType = _utils.PageNotFoundError;
32 | }
33 | const err = new ErrorType(serializedErr.message);
34 | err.stack = serializedErr.stack;
^
error: Invariant: Render expects to have requestAsyncStorage, none found
at /Users/xxx/xxx/xxx/node_modules/next/dist/server/lib/server-ipc/request-utils.js:34:30
Additional information
I also tried to use a server component instead and fetching the data using a route handler in an /api/ endpoint and the error is always the same
The text was updated successfully, but these errors were encountered:
What version of Bun is running?
1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b
What platform is your computer?
Darwin 23.0.0 arm64 arm
What steps can reproduce the bug?
I'm trying to fetch data from a JSON file stored locally to populate inputs and selects in a form with NextJS. The server component of the page uses the
useEffect
to fetch the data with a helper function like so:What is the expected behavior?
Be able to read a file locally as if it was being read from a script or using the
fs
module like so:Running the script with
bun run script.ts
works like a charm.What do you see instead?
Running the dev server with
yarn run dev
yields in the following error:Returns the following error:
Then, attempting with
bun --bun run dev
I get this error which I believe has some relation with this #5363:Additional information
I also tried to use a server component instead and fetching the data using a route handler in an /api/ endpoint and the error is always the same
The text was updated successfully, but these errors were encountered: