Broken CLI TypeScript support
See original GitHub issueEnvironment
Knex version: 0.20.15
Database + version: sqlite3
OS: macOS 10.14.6 (18G3020)
Example repository with bugs
https://github.com/htunnicliff/knex-cli-ts-errors
Bug (1)
Explain what kind of behaviour you are getting and how you think it should do
Running knex migrate:make some_migration_name
with a knexfile.ts
in the current working directory should produce a TypeScript migration file with no errors.
Error message
Failed to load external module ts-node/register
Failed to load external module typescript-node/register
Failed to load external module typescript-register
Failed to load external module typescript-require
Failed to load external module @babel/register
sqlite does not support inserting default values. Set the `useNullAsDefault` flag to hide this warning. (see docs http://knexjs.org/#Builder-insert).
Created Migration: /knex-cli-ts-errors/migrations/20200416104822_create_example_table.ts
Bug (2)
Explain what kind of behaviour you are getting and how you think it should do
Running knex migrate:up
should migrate with no errors.
Error message
Failed to load external module ts-node/register
Failed to load external module typescript-node/register
Failed to load external module typescript-register
Failed to load external module typescript-require
Failed to load external module @babel/register
sqlite does not support inserting default values. Set the `useNullAsDefault` flag to hide this warning. (see docs http://knexjs.org/#Builder-insert).
/knex-cli-ts-errors/migrations/20200416104822_create_example_table.ts:1
import * as Knex from "knex";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1072:16)
at Module._compile (internal/modules/cjs/loader.js:1122:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at FsMigrations.getMigration (/knex-cli-ts-errors/node_modules/knex/lib/migrate/sources/fs-migrations.js:81:12)
at /knex-cli-ts-errors/node_modules/knex/lib/migrate/Migrator.js:146:69
at arrayFilter (/knex-cli-ts-errors/node_modules/lodash/lodash.js:582:11)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:23 (1 by maintainers)
Top Results From Across the Web
Versions of @angular/compiler-cli and typescript could not be ...
The most common reason for this is a broken npm install. Please make sure your package.json contains both @angular/compiler-cli and typescript ...
Read more >Documentation - TypeScript 3.9
Visual Studio Code supports selecting different versions of TypeScript. ... This is a breaking change, but we believe most code was written with...
Read more >Building a TypeScript CLI with Node.js and Commander
In this tutorial, we will talk about the CLI is and how to use Commander.js with TypeScript to build one. We will then...
Read more >Announcing the Official TypeScript Types Public Preview
Ember Classic support. As specified in RFC 0800, there are also a number of breaking changes from the types in DefinitelyTyped regarding support...
Read more >API - esbuild
The API can be accessed in one of three ways: on the command line, ... You may also find the TypeScript type definitions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found a work around here: https://github.com/knex/knex/issues/3849#issuecomment-643411244
in my
package.json
added this line, then executed whatever command I want:and run a command in command-line like:
Note: My problem was that
esnext
is not supported for the knex cliWhat is the recommended workflow for running Typescript migrations? The documentation still suggests that running
knex migrate:latest
is sufficient:See: