lukeed / ley

(WIP) Driver-agnostic database migrations
MIT License
259 stars 14 forks source link

Improve TypeScript error message #33

Open karlhorky opened 1 year ago

karlhorky commented 1 year ago

When TypeScript is used in a migration file without tsm being installed + configured, the error message (Cannot use import statement outside a module) is a bit confusing:

$ yarn migrate up
yarn run v1.22.19
$ dotenv ley up

[ley] An error occurred:

      /Users/k/p/next-js-example-winter-2023-vienna-austria/migrations/1675675178-createTableAnimals.ts:1
    import { Sql } from 'postgres';
    ^^^^^^
    SyntaxError: Cannot use import statement outside a module
        at internalCompileFunction (node:internal/vm:73:18)
        at wrapSafe (node:internal/modules/cjs/loader:1176:20)
        at Module._compile (node:internal/modules/cjs/loader:1218:27)
        at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
        at Module.load (node:internal/modules/cjs/loader:1117:32)
        at Module._load (node:internal/modules/cjs/loader:958:12)
        at Module.require (node:internal/modules/cjs/loader:1141:19)
        at require (node:internal/modules/cjs/helpers:110:18)
        at exports.load (/Users/k/p/next-js-example-winter-2023-vienna-austria/node_modules/ley/lib/util.js:62:10)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

For this migration code:

import { Sql } from 'postgres'

export async function up(client: Sql) {}

export async function down(client: Sql) {}

Would be great if Ley could offer some additional details when such a failure occurs, such as:

If you're trying to use TypeScript in your migrations, install tsm and configure it using `ley -r tsm` in your package.json script. More details: https://github.com/lukeed/ley#typescript