lukeed / lukeed/ley

Improve TypeScript error message

Open
#33 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
271
Forks
13
PR merge metrics
No merged PRs in 30d

Description

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:

```bash
$ 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:

```ts
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
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how Ley reports the shown migration loading error and review the TypeScript setup described in the issue, including the package.json script using `ley -r tsm`. Confirm the improved message explains installing and configuring tsm, links to the Ley TypeScript documentation, and still reports other migration failures normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgres, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.