question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

runMigration doesn't support typescript files as input

See original GitHub issue

Expected Behavior

Something like the following should execute.

      const config: RunMigrationConfig = {
        filePath: 'someFilePath.ts',
        spaceId,
        environmentId,
        accessToken,
      };

      await runMigration(config);

Actual Behavior

The contentful-schema/1/00-languages.ts script could not be parsed, as it seems to contain syntax errors.

contentful-schema/1/00-languages.ts:1
import { MigrationFunction } from 'contentful-migration';
^^^^^^

Context

Trying to run multiple migration files in sequence based on various rules. It makes sense to use runMigration rather running command line calls from within a ts script.

Environment

Node Version: 12.19.0 “contentful-migration”: “^4.0.6”,

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
arminrosucommented, Jun 8, 2021

@phawxby I’m just running everything through ts-node, no compilation required and it loads typescript files without issue.

e.g. ts-node migration.ts where migration.ts is:

import { runMigration } from 'contentful-migration';

//...

await runMigration({
  filePath: '/users/johnny/someFilePath.ts',
  spaceId,
  environmentId,
  accessToken,
});

edit: updated the example to contain an absolute file path, as is required by runMigration, so people know about it.

2reactions
OriginalEXEcommented, Mar 4, 2021

For anyone getting a TypeError: migrationCreator is not a function error, make sure you use module.exports instead of export default. This is what your migration file would look like:

import { MigrationFunction } from "contentful-migration";

const migrate: MigrationFunction = (migration) => {
  
};

module.exports = migrate;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Migrating from JavaScript - TypeScript
During our JS to TS migration, we'll need to separate our input files to prevent TypeScript from overwriting them.
Read more >
TypeORM Migration: File must contain a TypeScript ...
I was just using npx typeorm migration:show -d ./src/data-source.ts and getting the same error as above ( File must contain a TypeScript ......
Read more >
How to migrate DBs with NodeJS and TypeScript - Medium
Migration of a database is a process of applying changes to the database. For example, in SQL it'd be creating/dropping/altering of tables, ...
Read more >
A simple guide for migrating from JavaScript to TypeScript
In that file, simply write declare module "my-module" (with the “my-module” being the package that doesn't have Typescript). Then, in your ...
Read more >
Incremental Migration from JavaScript to TypeScript in Our ...
And secondly, creating declaration files was also excellent for understanding the codebase better, if you were not already fully familiar with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found