I have the following docker-compose file:
version: '3.9'
services:
database:
image: mongo:3.6
restart: on-failure
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
volumes:
- mongo_data:/data/db
server:
restart: on-failure
image: parseplatform/parse-server:5.2.3
ports:
- 1337:1337
- 9229:9229
environment:
- PARSE_SERVER_APPLICATION_ID=$SERVER_APPLICATION_ID
- PARSE_SERVER_APPLICATION_NAME=$SERVER_APPLICATION_NAME
- PARSE_SERVER_MASTER_KEY=$SERVER_MASTER_KEY
- PARSE_SERVER_DATABASE_URI=mongodb://admin:admin@mongo/parse_server?authSource=admin
- PARSE_SERVER_MOUNT_GRAPHQL=true
- PARSE_SERVER_CLOUD=/parse-server/cloud/main.js
- PARSE_SERVER_GRAPH_QLSCHEMA=/parse-server/cloud/schema_2.graphql
links:
- database:mongo
depends_on:
- database
entrypoint: "node --inspect=0.0.0.0:9229 /parse-server/bin/parse-server"
volumes:
- parse_server_cloud:/parse-server/cloud
- ./parse-server/package.json:/parse-server/package.json
volumes:
mongo_data:
parse_server_cloud:
driver: local
driver_opts:
type: none
device: ./parse-server/cloud
o: bind
Project structure:
- docker
- parse-server
- cloud
main.js
generate_classes.js
My main.js:
import {createClassIfNotExists} from "./generate_classes";
createClassIfNotExists('SomeClassV10').then(r => console.log(r));
My generate_classes.js:
export const createClassIfNotExists = async (name) => {
const schema = new Parse.Schema(name);
schema.get().then(() => {
console.log('Class exists!');
}).catch(async (error) => {
schema.addString('name', {required: true});
schema.addNumber('age', {required: true});
await schema.save();
console.log('Class ' + name + ' was created');
});
}
When I am trying to run this via:
docker-compose up -d server
I am getting the following error inside my container:
import {createClassIfNotExists} from "./generate_classes";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at compileFunction (<anonymous>)
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at new ParseServer (/parse-server/lib/ParseServer.js:158:9)
Is this a bug or I am missing something?