-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: AsyncLocalStorage is not a constructor #32320
Comments
@averri, it would be helpful to be able to see the code to understand what is happening. I'm unable to recreate the issue locally. |
I cannot reproduce on 13.11.0 either. Are you sure that's the version you're running (you can add a |
Thanks @jasnell and @cjihrig. There was an issue with I was using the code inspired by Nodejs 13 documentation (ref: What steps will reproduce the bug?): const {AsyncLocalStorage} = require('async_hooks')
const http = require('http')
console.log(process.version)
const kReq = 'CURRENT_REQUEST'
const asyncLocalStorage = new AsyncLocalStorage()
function log(...args) {
const store = asyncLocalStorage.getStore()
// Make sure the store exists and it contains a request.
if (store && store.has(kReq)) {
const req = store.get(kReq)
// Prints `GET /items ERR could not do something
console.log(req.method, req.url, ...args)
} else {
console.log(...args)
}
}
http.createServer((request, response) => {
asyncLocalStorage.run(new Map(), () => {
const store = asyncLocalStorage.getStore()
store.set(kReq, request)
new Promise(resolve => {
log('INFO', 'sleeping...')
setTimeout(() => {
log('INFO', 'resolving...')
resolve()
}, 1000)
}).then(() => {
log('INFO', 'finished')
response.statusCode = 200
response.write('ok')
response.end()
})
})
})
.listen(8080) Running this code with Nodejs 13.11.0 and invoking GET at v13.11.0
GET /index INFO sleeping...
GET /index INFO resolving...
GET /index INFO finished
GET /favicon.ico INFO sleeping...
GET /favicon.ico INFO resolving...
GET /favicon.ico INFO finished ... which demonstrates that there are no issues. |
What steps will reproduce the bug?
Run the demo code provided in https://nodejs.org/api/all.html#async_hooks_class_asynclocalstorage
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
Nodejs should recognize all the API functions and run the example code with success.
What do you see instead?
The text was updated successfully, but these errors were encountered: