Skip to content

mime.charsets in Response.js is undefined #5567

Closed

Description

@robertlario

Using Express version 4.19.2 in Response.js at line 790 (var charset = mime.charsets.lookup(value.split(';')[0]);) is throwing an exception stating that mime.charset "TypeError: Cannot read properties of undefined (reading 'charsets')"

Activity

  1. wesleytodd commented on Mar 27, 2024

    @wesleytodd
    Member

    Can you post some example code where it is having this error behavior?

  2. robertlario commented on Mar 27, 2024

    @robertlario
    Author

    I am trying to run my code in serverless-offline.

    I do not call the code directly.

    Here is the stack trace:

    TypeError: Cannot read properties of undefined (reading 'charsets')
    at ServerResponse.header (..\node_modules\express\lib\response.js:790:1)
    at ServerResponse.contentType (..\node_modules\express\lib\response.js:625:1)
    at setContentTypeMiddleware (..\lib\router\middlewares\setContentType.js:15:1)
    at Layer.handle [as handle_request] (..\node_modules\express\lib\router\layer.js:95:1)
    at trim_prefix (..\node_modules\express\lib\router\index.js:328:1)
    at ..\node_modules\express\lib\router\index.js:286:1
    at Function.process_params (..\node_modules\express\lib\router\index.js:346:1)
    at next (..\node_modules\express\lib\router\index.js:280:1)
    at ..\lib\router\middlewares\setServerUrl.js:26:1
    at .webpack\service\src\index.js:154906:9 {stack: 'TypeError: Cannot read properties of undefine…oyment.webpack\service\src\index.js:154906:9', message: 'Cannot read properties of undefined (reading 'charsets')'}

    Here are my modules:
    @types/cors@2.8.17
    ├── @types/errorhandler@0.0.32
    ├── @types/express-serve-static-core@4.17.43
    ├── @types/express@4.17.21
    ├── @types/flat@5.0.5
    ├── @types/http-errors@1.8.2
    ├── @types/jest@26.0.24
    ├── @types/lodash@4.14.202
    ├── @types/mime-types@2.1.4
    ├── @types/mock-req-res@1.1.6
    ├── @types/node@12.20.55
    ├── @types/uuid@3.4.13
    ├── @typescript-eslint/eslint-plugin@4.33.0
    ├── @typescript-eslint/parser@4.33.0
    ├── ajv-errors@1.0.1
    ├── ajv@6.12.6
    ├── aws-sdk-mock@5.9.0
    ├── aws-sdk@2.1573.0
    ├── aws-xray-sdk@3.5.4
    ├── cors@2.8.5
    ├── errorhandler@1.5.1
    ├── eslint-config-airbnb-base@14.2.1
    ├── eslint-config-prettier@8.10.0
    ├── eslint-plugin-import@2.29.1
    ├── eslint-plugin-prettier@4.2.1
    ├── eslint@7.32.0
    ├── express@4.19.2
    ├── flat@5.0.2
    ├── force@0.0.3
    ├── http-errors@1.8.1
    ├── jest-each@26.6.2
    ├── jest-mock-extended@1.0.18
    ├── jest@26.6.3
    ├── lodash@4.17.21
    ├── mime-types@2.1.35
    ├── mime@4.0.1
    ├── mock-req-res@1.2.1
    ├── prettier@2.8.8
    ├── serverless-http@2.7.0
    ├── sinon@10.0.1
    ├── standard-version@9.5.0
    ├── supertest@6.3.4
    ├── ts-jest@26.5.6
    ├── typescript@4.9.5
    ├── uuid@8.3.2

  3. wesleytodd commented on Mar 27, 2024

    @wesleytodd
    Member

    I don't know what serverless offline is, but in the stack I see this is the closes thing that looks like user land code: at ..\lib\router\middlewares\setServerUrl.js:26:1

  4. robertlario commented on Mar 27, 2024

    @robertlario
    Author

    at line 34 in response.js

    var mime = send.mime;

    send.mime appears to be undefined.

    Any thoughts?

  5. wesleytodd commented on Mar 27, 2024

    @wesleytodd
    Member

    https://github.com/pillarjs/send/blob/master/index.js#L71

    I looked at that initially and am not sure how it could be. That is why I would need more to go off of to debug.

  6. wesleytodd commented on Mar 27, 2024

    @wesleytodd
    Member

    Also, the npm ls output you showed doesn't show these things afaict. If you think it is something with the packages installed please post more of the output.

  7. robertlario commented on Mar 27, 2024

    @robertlario
    Author

    It was a versioning issue! :-( What a nightmare!

    Please consider the issue closed. Thank you for your help!

  8. wesleytodd commented on Mar 27, 2024

    @wesleytodd
    Member

    Haha, no problem. Glad you got it sorted out!

  9. wilcoxmd commented on Mar 8, 2025

    @wilcoxmd

    Hey @robertlario any chance you remember the solution to this? I'm currently debugging and suspected a versioning issue as well! Just trying to find the right thing to update.

  10. locked and limited conversation to collaborators on Mar 8, 2025
  11. converted this issue into a discussion #6380 on Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions