简体   繁体   English

打字稿const导出和导入不起作用?

[英]typescript const export and import is not working?

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). 我正在使用打字稿2.3,并尝试导出一个简单的const,并在另一个文件中使用它(我在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." 在chrome中,在翻译后的ts1.js文件中显示“未捕获的语法错误;意外的令牌导出”。 here is my tsconfig file if that helps: 这是我的tsconfig文件,如果有帮助的话:

{
  "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? 有人可以帮我吗?

它的工作原理完美无缺,您可以尝试检查您的polyfills working link

You have "module": "es6", ES6 modules don't work in the browser right now. 您具有"module": "es6", ES6模块目前无法在浏览器中使用。

Recommended fix 推荐的修复

Please use module: commonjs with webpack . 请使用module: commonjs和webpack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM