[SOLVED] CLI Migration: autogeneration generates invalid code (& can't run such migration on sandbox)

[SOLVED]
Turns out it was some version conflict, I had a @datocms/cli@1.0.21 in devDependencies along with a global install npm i -g @datocms/cli@latest and they were not playing well. I bumped my devDependency to @datocms/cli@2.0.0 and now the migration is created and runs fine (although the autogen still imports SimpleSchemaTypes by mistake and I get a warning that it’s not used)

Describe the issue:

I’m back working in a project where we used to perform migrations using the CLI. It worked smoothly in the past, but now I need to perform a migration and the autogeneration is producing invalid code from the beginning:


Errors are:

Running migration "1710251840_release23.ts"... !
TSError: β¨― Unable to compile TypeScript:
error TS2345:
Argument of type '{ id: string; name: string; api_key: string; modular_block: true; inverse_relationships_enabled: false; }'
is not assignable to parameter of type 'ItemTypeCreateSchema'.
Object literal may only specify known properties, and 'id' does not exist in type 'ItemTypeCreateSchema'.
error TS2339:
Property 'schemaMenuItems' does not exist on type 'Client'.
(IDE-only warning):
'SimpleSchemaTypes' is declared but its value is never read.ts(6133)

My steps were:

Install tool:
npm -g install @datocms/cli@latest

Check version:
@datocms/cli/2.0.0 darwin-x64 node-v20.11.0

Autogenerate migration script:
datocms migrations:new 'release23' --autogenerate=release-23:main --api-token=...

Then apply in a new sandbox (fails):
datocms migrations:run --destination=staging --api-token=...

I’m not really sure what might be going on.

Thanks for the help!

Glad you were able to figure it out, and thanks for coming back here to amend your post afterward!