Search code examples
node.jsstrapi

Strapi database error SyntaxError: Unexpected token '.' targetAttribute?.target === uid


I've update my Strapi version from 4.3.6 to 4.4.5 and got this error when I start appliation with production environment with command npm run start

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
/home/megapolisgit/megapolis-platform/node_modules/@strapi/database/lib/entity-manager/morph-relations.js:15
      targetAttribute?.target === uid &&
                      ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/megapolisgit/megapolis-platform/node_modules/@strapi/database/lib/entity-manager/index.js:21:66)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

node version is 17.9.1 db: PostgreSQL 14.2

I've checked github repository for answer but haven't found the same issues


Solution

  • Finally, I found an answer. The problem was in PM2 I used to run my strapi. By default, PM2 takes node binary from /usr/bin/node in my case it was 12.22.12. Using NVM I've installed 18.12.1 but the path to this was different. I changed ecosystem.config.js to this

    module.exports = {
      apps: [
        {
          name: 'app',
          script: 'npm',
          args: 'start',
          env_production: {
           NODE_ENV: "production"
          },
          interpreter: "/home/mega/.nvm/versions/node/v18.12.1/bin/node"
        },
      ],
    };
    

    and got my application running with the correct node version.