bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
110 stars 4 forks source link

Unexpected token 'export' on `npx directus schema-sync export` #38

Closed martin-braun closed 4 months ago

martin-braun commented 5 months ago

Describe the Bug

When I try to export my schema and data after installing the config files, I get:

(node:53394) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
[17:45:56.016] INFO: Loaded extensions: directus-extension-schema-sync
[17:45:56.020] INFO: Exporting everything to: /Users/marty/.sources/github.com/martin-braun/gf-server/schema-sync/data
[17:45:56.030] ERROR: Unexpected token 'export'
    err: {
      "type": "SyntaxError",
      "message": "Unexpected token 'export'",
      "stack":
          /Users/marty/.sources/github.com/martin-braun/gf-server/schema-sync/directus_config.js:12
          export const syncDirectusCollections = {
          ^^^^^^

          SyntaxError: Unexpected token 'export'
              at internalCompileFunction (node:internal/vm:73:18)
              at wrapSafe (node:internal/modules/cjs/loader:1178:20)
              at Module._compile (node:internal/modules/cjs/loader:1220:27)
              at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
              at Module.load (node:internal/modules/cjs/loader:1119:32)
              at Module._load (node:internal/modules/cjs/loader:960:12)
              at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)

My package.json, that was generated, is:

{
  "name": "gf-server",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "directus database migrate:latest && directus start",
    "export": "directus schema-sync export"
  },
  "keywords": [],
  "author": "CT",
  "license": "ISC",
  "dependencies": {
    "directus": "^10.10.7",
    "pg": "^8.11.5",
    "directus-extension-schema-sync": "^1.6.4"
  },
  "devDependencies": {
    "@directus/extension-toolkit": "^0.8.0",
    "npm-run-all": "^4.1.5",
    "rimraf": "^5.0.5"
  }
}

I haven't modified the schema-sync files yet, but looking at those I can see how it should already work for users, roles, etc.

To Reproduce

Version

1.6.4

Installed Extension Via

NPM Custom

martin-braun commented 5 months ago

Fixed by putting "type": "module", into the package.json, could you please update the documentation. Directus does not initialize with this line in the package.json.

Thanks.