Skip to content

Commit 87c5590

Browse files
committed
catch esm error
1 parent 169f314 commit 87c5590

File tree

5 files changed

+7
-20
lines changed

5 files changed

+7
-20
lines changed

spec/CloudCode.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ describe('Cloud Code', () => {
4545
);
4646
});
4747

48-
it('can use import for cloud files', async () => {
49-
await reconfigureServer({
50-
cloud: './spec/cloud/cloudCodeRelativeFile.js',
51-
module: true,
52-
});
53-
const result = await Parse.Cloud.run('cloudCodeInFile', {});
54-
expect(result).toBe('It is possible to define cloud code in a file.');
55-
});
56-
5748
it('can create functions', done => {
5849
Parse.Cloud.define('hello', () => {
5950
return 'Hello world!';

src/Options/Definitions.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ module.exports.ParseServerOptions = {
260260
env: 'PARSE_SERVER_MIDDLEWARE',
261261
help: 'middleware for express server, can be string or function',
262262
},
263-
module: {
264-
env: 'PARSE_SERVER_MODULE',
265-
help: 'Whether cloud should load using `import` instead of `require`.',
266-
action: parsers.booleanParser,
267-
},
268263
mountGraphQL: {
269264
env: 'PARSE_SERVER_MOUNT_GRAPHQL',
270265
help: 'Mounts the GraphQL endpoint',

src/Options/docs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
* @property {Number|String} maxLogFiles Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)
5050
* @property {String} maxUploadSize Max file size for uploads, defaults to 20mb
5151
* @property {Union} middleware middleware for express server, can be string or function
52-
* @property {Boolean} module Whether cloud should load using `import` instead of `require`.
5352
* @property {Boolean} mountGraphQL Mounts the GraphQL endpoint
5453
* @property {String} mountPath Mount path for the server, defaults to /parse
5554
* @property {Boolean} mountPlayground Mounts the GraphQL Playground - never use this option in production

src/Options/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ export interface ParseServerOptions {
7070
databaseAdapter: ?Adapter<StorageAdapter>;
7171
/* Full path to your cloud code main.js */
7272
cloud: ?string;
73-
/* Whether cloud should load using `import` instead of `require`. */
74-
module: ?boolean;
7573
/* A collection prefix for the classes
7674
:DEFAULT: '' */
7775
collectionPrefix: ?string;

src/ParseServer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ class ParseServer {
103103
if (typeof cloud === 'function') {
104104
cloud(Parse);
105105
} else if (typeof cloud === 'string') {
106-
if (this.config.module) {
107-
import(path.resolve(process.cwd(), cloud));
108-
} else {
106+
try {
109107
require(path.resolve(process.cwd(), cloud));
108+
} catch (e) {
109+
if (e.code === 'ERR_REQUIRE_ESM') {
110+
import(path.resolve(process.cwd(), cloud));
111+
} else {
112+
throw e;
113+
}
110114
}
111115
} else {
112116
throw "argument 'cloud' must either be a string or a function";

0 commit comments

Comments
 (0)