I'm a newbie to TypeScript and currently using Knex to build a template table in our PostgreSQL database. On this file and others and am continually running in to this same issue with TypeScript, code is as follows:
import * as Knex from 'knex';
exports.up = async (knex: Knex): Promise<void> => {
await knex.schema.raw(`
CREATE TABLE test (
test TEXT NOT NULL,
tes2 INTEGER NOT NULL,
PRIMARY KEY (key, website)
)
`);
}
exports.down = async (knex: Knex): Promise<void> => {
await knex.schema.dropTable('test');
}
and I get this error:
import * as Knex from 'knex';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I have also tried these varients:
import * as Knex = require('knex');
import { * as Knex } from 'knex';
const * = require('knex');
const { * as Knex } = require('knex');
But I cannot find any solution online which seems to solve the problem.
Any help on this would be awesome.
question from:
https://stackoverflow.com/questions/65883600/typescript-knex-cannot-use-import-statement-outside-a-module 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…