Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlisar Fares-Boulos
203 Pointscould you please explain how to use the compiler if you did not install typescript globally? thanks
I tried "npx tsc" to compile to js but "export" keeps throwing a unexpected token error.
1 Answer
Travis Alstrand
Treehouse Project ReviewerIt's a bit hard to tell without having your project on hand, but did you happen to write your filename after npx tsc
?
Here's what I found after some Googling
Since you are getting an "unexpected token" error related to the export keyword, it is likely because your environment doesn't support the version of JavaScript that includes export and import. Could you try adding the following line to the top of your TypeScript file?
export {};
This will create a module in your file, which will allow you to use export and import statements.
Alisar Fares-Boulos
203 PointsAlisar Fares-Boulos
203 PointsMy mistake, I see now that it's written further up the error msg that I needed to add "type": "module" to package.json. Thanks for the help!
Travis Alstrand
Treehouse Project ReviewerTravis Alstrand
Treehouse Project ReviewerOh, nice job figuring it out!!