2
votes

I'm trying to do simple import/export in TypeScript as follows:

animals.ts

export const someVar=5;

main.ts

import {someVar} from './animals';

But compiler is saying:

Compilation errors

Below are my typescript compiler options:

-t ES6 -m commonjs

I've tried amd in module options as well but with no luck. RequireJs seems to be working fine though.

My TypeScript version is 2.2.2 and using WebStorm IDE.

What am I missing here? Please bear with me as I am new to this.

Edit

tsc main.ts compiles perfectly fine. But WebStorm still whining about compilation errors.

1
What's your tsconfig.json look like? How do you turn the typescript sources into js ones? Via regular tsc? Do you use webpack or gulp or babel etc? - Horia Coman
I'm using tsc inbuit into webstorm without tsconfig.json. But giving below compiler options from settings view -t ES6 -m commonjs - Shanu Gupta
For all intents and purposes this is very basic stuff which should work. I think there's something wrong with the webstorm js config. You should try running tsc outside it, from a command line, and check to see it works. - Horia Coman
@HoriaComan you are so right, tsc main.ts does compile correctly without errors. Somethings just wrong with Webstorm I guess. - Shanu Gupta
Did you set the configuration "Languages & Frameworks" => JavaScript to ECMAScript 6? - str

1 Answers

1
votes

Found the solution. I was using old webstorm 10 that was using typescript compiler version 1.4. I upgraded the webstorm to 2017.1 which uses compiler version 2.2.2. Thanks @Horia Coman for giving hint.