typescript const export and import is not working?

4.3k views Asked by At

I m using typescript 2.3 and trying to export a simple const and using it in another file (i have done this countless times in es6). somehow it is not working and i have no idea whats wrong? here is the code:

export const abc: string = "dd"; (ts1.ts)
import { abc }  from './ts1'; (ts2.ts)

in chrome, in the translated ts1.js file it is showing "uncaught syntax error; unexpected token export." here is my tsconfig file if that helps:

{
  "compileOnSave": true,
  "compilerOptions": {
    "allowJs": false,
    "module": "es6",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "target": "es5",
    "types" :  [] 
  },
  "include": [
    "app",
    "tests"
  ],
  "exclude": [ "content", "node_modules", "bower_components", "Scripts" ],
  "typeAcquisition": {
    "enable": true
  }

can some one plz help me out?

2

There are 2 answers

0
Rahul Singh On

Its works flawlessly you can try checking your polyfills working link

0
basarat On

You have "module": "es6", ES6 modules don't work in the browser right now.

Recommended fix

Please use module: commonjs with webpack.