Migration Error

Hi im trying to run a migration like this

datocms migrations:run --source=feature-branch --in-place

and receive this error

{
  "error": {
    "message": "Unexpected token 'export'"
  }

this is the migration file

import { Client } from '@datocms/cli/lib/cma-client-node';


export default async function addTopics(client: Client) {
  // DatoCMS migration script

  // For more examples, head to our Content Management API docs:
  // https://www.datocms.com/docs/content-management-api

  // Create an Article model:
  // https://www.datocms.com/docs/content-management-api/resources/item-type/create

  const topicModel = await client.itemTypes.create({
    name: 'Article',
    api_key: 'article',
  });

  // Create a Title field (required):
  // https://www.datocms.com/docs/content-management-api/resources/field/create

  const titleField = await client.fields.create(topicModel, {
    label: 'Title',
    api_key: 'title',
    field_type: 'string',
    validators: {
      required: {},
    },
  });

  // Create an Article record:
  // https://www.datocms.com/docs/content-management-api/resources/item/create

  const article = await client.items.create({
    item_type: topicModel,
    title: 'My first topic!',
  });
}

It must be some silly bug but cannot fix it

Hello @gaston.e.coria and welcome to the community

This can be happen if TypeScript modules are not set to โ€œcommonjsโ€, and are set to โ€œesnextโ€ instead.

Could you try and replace it in your typescript configuration file, re-run npm install, and re-try the migration?

Let me know if it works

1 Like

Thanks it was that :smiley: