Skip to content

Cannot specify cloud file string using ES Module #7559

Open

Description

@dblythy

New Issue Checklist

Issue Description

When using Parse Server with "type": "module", it is not possible to set a cloud string, as it returns Must use import to load ES Module.

Steps to reproduce

Create a Parse Server with "type": "module" (such as parse-community/parse-server-example#400), set cloud file string

Actual Outcome

Error: Must use import to load ES Module: /Users/daniel/GitHub/parse-server-example/cloud/main.js require() of ES modules is not supported.

Expected Outcome

Cloud function to work

Workaround

() => import('./cloud/main.js'),

Environment

Server

  • Parse Server version: 4.10.3
  • Operating system: MacOS
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Localhost

Activity

  1. parse-github-assistant commented on Sep 9, 2021

    @parse-github-assistant

    Thanks for opening this issue!

    • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
  2. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    on Sep 9, 2021
  3. mtrezza commented on Sep 14, 2021

    @mtrezza
    Member

    Closed via #7560

  4. mtrezza commented on Nov 12, 2023

    @mtrezza
    Member

    @Moumouls Can we merge #7560 again? Your comment led to a revert, but since Parse Server 6 supports an async start, the issue your mentioned should be solved and we can merge this, right?

    There is also #7914 and #8232, but I believe that the issue here hasn't been addressed in these. If so, then we'd just have to reopen #7560 and merge, maybe with some slight modifications.

  5. mtrezza commented on Nov 15, 2023

    @mtrezza
    Member

    @dblythy Is this issue already resolved?

  6. mtrezza commented on Nov 17, 2023

    @mtrezza
    Member

    I was able to reproduce the issue with Parse Server 6.5.0-beta.1 where setting a ESM for the cloud property of Parse Server throws the error:

    Error [ERR_REQUIRE_ESM]: require() of ES Module main.js from node_modules/parse-server/lib/ParseServer.js not supported.
    Instead change the require of main.js in node_modules/parse-server/lib/ParseServer.js to a dynamic import() which is available in all CommonJS modules.
    

    Issue reopened.

  7. added
    bounty:$5Bounty applies for fixing this issue (Parse Bounty Program)
    on Nov 17, 2023
  8. mman commented on Oct 9, 2024

    @mman
    Contributor

    The fix integrated in #7560 relies on process.env.npm_package_type being set to module, so in my case when I start Parse Server via node index.js I get:

    process.env.npm_package_type: undefined and therefore Parse Server falls back to require.

  9. mman commented on Oct 9, 2024

    @mman
    Contributor

    The variable npm_package_type is coming from npm. But anyway logic depending on it is rather unreliable and we better document it properly somewhere :)

    I was able to workaround this by hardcoding the value in my K8S deployment where I actually start node directly like this:

          containers:
          - name: XXX
            image: docker.io/YYY
            imagePullPolicy: Always
            command: ["node", "--trace-deprecation", "index.js"]
            env:
            - name: npm_package_type
              value: "module"
            - name: PARSE_MOUNT
              value: "/XXX"
            - name: PARSE_PUBLIC_SERVER_URL
              value: "ZZZ"
    

    and then the parse server starts again.

  10. mman commented on Oct 14, 2024

    @mman
    Contributor

    I can confirm that after switching the K8S deployment to use npm start to start the Parse Server, the npm_package_type is properly set to module and ParseServer starts using import instead of require.

    Now that I think about it it makes sense, as starting the app directly via node probably completely ignores the package.json, whereas using npm start actually infers the module type from `package.json.

  11. djdannycastillo commented on Dec 7, 2024

    @djdannycastillo

    The variable npm_package_type is coming from npm. But anyway logic depending on it is rather unreliable and we better document it properly somewhere :)

    I was able to workaround this by hardcoding the value in my K8S deployment where I actually start node directly like this:

          containers:
          - name: XXX
            image: docker.io/YYY
            imagePullPolicy: Always
            command: ["node", "--trace-deprecation", "index.js"]
            env:
            - name: npm_package_type
              value: "module"
            - name: PARSE_MOUNT
              value: "/XXX"
            - name: PARSE_PUBLIC_SERVER_URL
              value: "ZZZ"
    

    and then the parse server starts again.

    @mman you've saved me a lot of time with this. I definitely agree with you on documenting this somewhere.

  12. removed
    bounty:$5Bounty applies for fixing this issue (Parse Bounty Program)
    on Mar 22, 2026
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:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions