Skip to content

Move to ECMAScript ES Module Import statements from require #9316

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

Closed
R3D347HR4Y opened this issue Sep 26, 2024 · 6 comments
Closed

Move to ECMAScript ES Module Import statements from require #9316

R3D347HR4Y opened this issue Sep 26, 2024 · 6 comments
Labels
state:duplicate Duplicate of already reported issue type:feature New feature or improvement of existing feature

Comments

@R3D347HR4Y
Copy link

R3D347HR4Y commented Sep 26, 2024

New Feature / Enhancement Checklist

Current Limitation

Using require is the old way of coding, most of my code needs to be converted to this crappy syntax when moving to cloud code

Feature / Enhancement Description

Use import instead of require in the whole project

Example Use Case

Not having to rewrite code to an old way of doing

Alternatives / Workarounds

Thanks to @mtrezza here is a workaround:
Creating a main.cjs file in the cloud folder and pointing to it in the Parse Server Config

(async () => {
  await import('./main.js');
})();

3rd Party References

Litteraly every single big node based project
Would also recommend using hono and deno to get a massive performance boost

Copy link

parse-github-assistant bot commented Sep 26, 2024

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Sep 27, 2024
@mtrezza
Copy link
Member

mtrezza commented Sep 27, 2024

I need to require Parse server as a CommonJS file and put anything regarding it in a .cjs

You could "import" (not "require") Parse Server like so:

import { ParseServer } from 'parse-server';

If you are referring to the Cloud Code file, then this may be a duplicate of #7559?

If you mean something else, then please provide more details and example code to explain the issue.

@mtrezza mtrezza added type:question Support or code-level question and removed type:feature New feature or improvement of existing feature labels Sep 27, 2024
@R3D347HR4Y
Copy link
Author

R3D347HR4Y commented Sep 27, 2024 via email

@mtrezza
Copy link
Member

mtrezza commented Sep 27, 2024

Is this then a duplicate of #7559?

A workaround would be to create a file main.cjs and set it in the Parse Server option for cloud:

(async () => {
  await import('./main.js');
})();

The file imports a ESM to make it available via CommonJS. This doesn't require any code rewriting.

@mtrezza mtrezza added type:feature New feature or improvement of existing feature state:duplicate Duplicate of already reported issue and removed type:question Support or code-level question state:duplicate Duplicate of already reported issue labels Sep 27, 2024
@R3D347HR4Y
Copy link
Author

Is this then a duplicate of #7559?

A workaround would be to create a file main.cjs and set it in the Parse Server option for cloud:

(async () => {
  await import('./main.js');
})();

The file imports a ESM to make it available via CommonJS. This doesn't require any code rewriting.

This works perfectly!
Should absolutely be noted in the doc for cloud code I think, I've been using Parse Server & Cloud Code for 4 years now and I never had such a simple trick to use ES6 Imports in CommonJS environnements

@mtrezza
Copy link
Member

mtrezza commented Oct 10, 2024

Closing as duplicate of #7559

@mtrezza mtrezza closed this as completed Oct 10, 2024
@mtrezza mtrezza added the state:duplicate Duplicate of already reported issue label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:duplicate Duplicate of already reported issue type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

2 participants