Skip to content

Cannot read properties of undefined (reading 'startsWith') #2

@imcm7

Description

@imcm7

Environment

  • Operating System: Linux
  • Node Version: v20.6.1
  • Nuxt Version: 3.7.3
  • CLI Version: 3.9.0
  • Nitro Version: 2.6.3
  • Package Manager: bun@1.0.2

Reproduction

import { useCompression } from 'h3-compression';

export default defineNitroPlugin((nitroApp) => {
    nitroApp.hooks.hook('render:response', async (response, { event }) => {
        if (!response.headers?.['content-type'].startsWith('text/html')) {  // undefined response.headers?.['content-type']
            return;
        }

        await useCompression(event, response);
    });
});

Describe the bug

I not see it any more, may be that case is registered when some errors is in nuxt config.

Cannot read properties of undefined (reading 'startsWith')
at (./server/plugins/compression.ts:9:1)
at ./node_modules/hookable/dist/index.mjs:48:66
at ./node_modules/hookable/dist/index.mjs:48:56
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at (./node_modules/nitropack/dist/runtime/renderer.mjs:29:5)
at async Object.handler (./node_modules/h3/dist/index.mjs:1630:19)
at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1840:7)

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions