watermarkchurch/contentful-schema-diff

script could not be parsed

alana314 opened this issue · 4 comments

Hello,
Thanks for creating this script!
I'm trying to call runMigration() on the generated ts file from the script, and it says "The 20200125001610_generated_diff_event.ts script could not be parsed, as it seems to contain syntax errors."
I also tried via contentful space migration, and I'm getting the same error with more detail:

import Migration, { MigrationFunction } from "contentful-migration";  
^^^^^^  
SyntaxError: Cannot use import statement outside a module  

I tried creating a similar tsconfig.json as in the project, and running ts-node --project tsconfig.json migrateEvents.ts, but it still gives the same error.

Hi Jordan!

The tool currently generates typescript files by default, and you need to run the file the way that it's described in the contentful-migration readme here: https://github.com/contentful/contentful-migration#writing-migrations-in-typescript

One thing that's been on the wish list for a while is a command line flag that would have the tool generate javascript files instead of typescript files. If you'd like to submit a PR for that we'd merge it!

Thanks for that! I'm still getting the same error though:
ts-node node_modules/.bin/contentful-migration -s [spaceid] 20200125001338_generated_diff_event.ts
The 0200125001338_generated_diff_event.ts script could not be parsed, as it seems to contain syntax errors.

I believe it fails on the first line, import Migration, { MigrationFunction } from "contentful-migration";

Usually when I get that error, it's due to Typescript targeting a version of JavaScript (aka ECMAScript aka ES) that the NodeJS runtime doesn't support. If your Typescript tsconfig.json is targeting ES6, then ts-node is going to leave those import statements alone instead of turning them into something like var Migration = require("contentful-migration"). Try making sure your tsconfig.json sets the compliation target to ES3.

Thank you! I was using global ts-node, I had to either use node_modules/.bin/ts-node or specify --project tsconfig.json for it to work.