aymericzip / aymericzip/intlayer
Intlayer + NextJS custom server does not work. (AsyncLocalStorage issues)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 833
- Forks
- 126
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 7
Description
I figured I'd post this here, incase anyone else has the same trouble I had.
I am using Next with a custom server. As soon as I added Intlayers to the project Next didn't want to start.
c:\repos\project\node_modules\next\dist\server\app-render\async-local-storage.js:44 throw sharedAsyncLocalStorageNotAvailableError; ^ Error: Invariant: AsyncLocalStorage accessed in runtime where it is not available at Object.<anonymous>
I found a solution through this comment for turborepo .. though unrelated .. I don't even use that package.
https://github.com/vercel/turborepo/issues/3319#issuecomment-2733804760
And then started my server somewhat like this.
const { asyncLocalStorage } = require('./asyncStorage.mjs');
import { createServer } from 'node:http';
import express from 'express';
const app = next({ dev, conf: nextConfig, customServer: true });
const handler = nextApp.getRequestHandler();
nextApp.prepare().then(() => {
const app = express();
app.all('*', (req, res) => {
return asyncLocalStorage.run(new Map(), () => {
return handler(req, res);
});
});
const httpServer = createServer(app);
httpServer
.once('error', (err) => {
console.error(err);
process.exit(1);
})
.listen(3000);
});
Maybe you can fix it so this is unnecessary .. either way I hope this solution helps someone.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the startup failure with a Next.js custom server using Intlayer, then inspect the asyncStorage.mjs workaround and the custom server setup shown in the issue. Done means the application starts and handles requests without requiring the manual AsyncLocalStorage wrapper.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, nextjs, node.js, typescript
- Domain
- backend, internationalization, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100