简体   繁体   English

未捕获的 SyntaxError:在从 Typescript 编译的代码中

[英]Uncaught SyntaxError: in code compiled from Typescript

I used my Build Javascript code in an html file and I'm getting this error:我在 html 文件中使用了我的 Build Javascript 代码,但出现此错误:

Uncaught SyntaxError: The requested module './calculate.js' does not provide an export named 'calculate'未捕获的语法错误:请求的模块“./calculate.js”不提供名为“calculate”的导出

Here is the Typescript.这是打字稿。 I don't know what I'm doing wrong.我不知道我做错了什么。

class calculate{

    public firstNumber:string;
    public secondNumber:string;
    public resultBox:string;
    constructor() { }


    greet(){
        console.log("Hello my");
    }


}

export {calculate};

Here is the JavaScript code:这是 JavaScript 代码:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class calculate {
    constructor() { }

    greet() {
        console.log("Hello my");
    }
}
exports.calculate = calculate;

Here is my HTML file:这是我的 HTML 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>

</body>
<script  type="module">

import {calculate} from './calculate.js'
 var cal= new calculate();
cal.greet();
</script>
</html>

You are compiling to commonjs module format.您正在编译为 commonjs 模块格式。 Specify module code generation to be "ES2015" by setting "module":"ES2015" in config or using --module cli argument.通过在配置中设置"module":"ES2015"或使用--module cli 参数将模块代码生成指定为 "ES2015"。

Demo 演示

暂无
暂无

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

相关问题 将已编译的 Typescript 文件相互导入时出现“未捕获的语法错误:无法在模块外使用 import 语句” - “Uncaught SyntaxError: Cannot use import statement outside a module” when importing compiled Typescript files to each other 从coffeescript编译的jQuery代码中未捕获的ReferenceError - Uncaught ReferenceError in jquery code compiled from coffeescript 从 NodeJS 中的 html 调用 TypeScript 编译代码 - Calling TypeScript compiled code from html in NodeJS 在编译之前从 typescript 代码中提取数据 - Extracting data from typescript code before it is compiled 运行编译的 Javascript 代码时,TypeScript 文件中出现“语法错误:无法在模块外使用导入语句”错误 - "SyntaxError: Cannot use import statement outside of a module" error in a TypeScript file when running compiled Javascript code 打字稿发布后编译:语法错误:错误的令牌{ - Post TypeScript Compilation: Uncaught SyntaxError: Unexpected token { 在 TypeScript 中导入时出现“Uncaught SyntaxError: Unexpected token {” - "Uncaught SyntaxError: Unexpected token {" when importing in TypeScript TS文档提供的小型编译的Typescript代码崩溃 - Small compiled Typescript code provided from TS documentation crashes 未捕获的语法错误:我的 Javascript 代码中有意外的字符串 - Uncaught SyntaxError: Unexpected string in my Javascript code 是什么导致此代码示例中的&#39;Uncaught SyntaxError:missing)&#39;? - What causes the 'Uncaught SyntaxError: missing )' in this code example?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM