Pkg: Compilation works but execution failed "SyntaxError: Cannot use import statement outside a module"

Created on 27 Apr 2020  路  2Comments  路  Source: vercel/pkg

Hello,

What happened:
Compilation good but not start. Got error.

In packages.json add :

"bin": "dist/app.js",
...
"pkg": {
    "assets": [
      ".env",
      "node_modules/acorn/**/*",
      "node_modules/app-root-path/**/*",
      "node_modules/axios/**/*",
      "node_modules/bcrypt/**/*",
      "node_modules/chalk/**/*",
      "node_modules/class-transformer/**/*",
      "node_modules/class-validator/**/*",
      "node_modules/commander/**/*",
      "node_modules/compression/**/*",
      "node_modules/copyfiles/**/*",
      "node_modules/cors/**/*",
      "node_modules/dotenv/**/*",
      "node_modules/event-dispatch/**/*",
      "node_modules/express/**/*",
      "node_modules/express-basic-auth/**/*",
      "node_modules/faker/**/*",
      "node_modules/figlet/**/*",
      "node_modules/formidable/**/*",
      "node_modules/glob/**/*",
      "node_modules/helmet/**/*",
      "node_modules/hummus-recipe/**/*",
      "node_modules/jsonfile/**/*",
      "node_modules/jsonwebtoken/**/*",
      "node_modules/lodash/**/*",
      "node_modules/microframework-w3tec/**/*",
      "node_modules/moment/**/*",
      "node_modules/morgan/**/*",
      "node_modules/multer/**/*",
      "node_modules/mysql/**/*",
      "node_modules/node-cron/**/*",
      "node_modules/node-fetch/**/*",
      "node_modules/nps/**/*",
      "node_modules/nps-utils/**/*",
      "node_modules/pdffiller/**/*",
      "node_modules/php-serialize/**/*",
      "node_modules/reflect-metadata/**/*",
      "node_modules/routing-controllers/**/*",
      "node_modules/serve-favicon/**/*",
      "node_modules/ssh2-sftp-client/**/*",
      "node_modules/supertest/**/*",
      "node_modules/ts-node/**/*",
      "node_modules/tslint/**/*",
      "node_modules/typedi/**/*",
      "node_modules/typeorm/**/*",
      "node_modules/typeorm-seeding/**/*",
      "node_modules/typeorm-typedi-extensions/**/*",
      "node_modules/typescript/**/*",
      "node_modules/uuid/**/*",
      "node_modules/winston/**/*"
    ]
  }

What you expected to happen:
When I do with https://github.com/w3tecch/express-typescript-boilerplate and do : pkg .

It create files "sl-server-macos", "sl-server-linux". But when I do : ./sl-server-macos

And have an error :
error: [:snapshot/sl-server-pkgapp] Application is crashed: SyntaxError: Cannot use import statement outside a module

Thanks for help

Most helpful comment

same

All 2 comments

I have the same issue. I have "type": "module" in my package.json.

same

Was this page helpful?
0 / 5 - 0 ratings