Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

script could not be parsed #49

Closed
alana314 opened this issue Jan 27, 2020 · 4 comments
Closed

script could not be parsed #49

alana314 opened this issue Jan 27, 2020 · 4 comments

Comments

@alana314
Copy link

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.

@gburgett
Copy link
Member

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!

@alana314
Copy link
Author

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";

@gburgett
Copy link
Member

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.

@alana314
Copy link
Author

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants