Skip to content
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

Cannot specify cloud file string using ES Module #7559

Open
4 tasks done
dblythy opened this issue Sep 9, 2021 · 9 comments
Open
4 tasks done

Cannot specify cloud file string using ES Module #7559

dblythy opened this issue Sep 9, 2021 · 9 comments
Labels
bounty:$5 Bounty applies for fixing this issue (Parse Bounty Program) type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@dblythy
Copy link
Member

dblythy commented Sep 9, 2021

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
@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 9, 2021

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.

@dblythy dblythy added the type:bug Impaired feature or lacking behavior that is likely assumed label Sep 9, 2021
@mtrezza
Copy link
Member

mtrezza commented Sep 14, 2021

Closed via #7560

@mtrezza mtrezza closed this as completed Sep 14, 2021
@dblythy dblythy reopened this Jan 28, 2022
@mtrezza
Copy link
Member

mtrezza commented Nov 12, 2023

@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.

@dblythy dblythy closed this as completed Nov 15, 2023
@mtrezza
Copy link
Member

mtrezza commented Nov 15, 2023

@dblythy Is this issue already resolved?

@mtrezza mtrezza reopened this Nov 17, 2023
@mtrezza
Copy link
Member

mtrezza commented Nov 17, 2023

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.

@mman
Copy link
Contributor

mman commented Oct 9, 2024

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.

@mman
Copy link
Contributor

mman commented Oct 9, 2024

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
Copy link
Contributor

mman commented Oct 14, 2024

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.

@djdannycastillo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$5 Bounty applies for fixing this issue (Parse Bounty Program) type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants