微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未捕获的ReferenceError:出口未定义// 2020年

如何解决未捕获的ReferenceError:出口未定义// 2020年

我被困住了。我尝试了许多解决方案,但都无济于事。 尝试实现模块时,出现以下错误消息:

未捕获的ReferenceError:未定义导出

我尝试了solution from Stack Overflow,但是它不起作用。更改tsconfing中的任何内容都没有任何区别。我在HTML文件的脚本中添加var exports = {};错误从“导出”更改为“需要”-死胡同。

服务器节点:

var fs = require('fs');
const express = require('express');
var path = require('path');
var { request } = require('http');
var app = express();
app.use(express.static(path.join(__dirname,'public')));
app.listen(3533);

html:

   <!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="description" content="testing site">
<Meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="style.css">
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>simple testin </title>
</head>
<body >
</body>
<script type="text/javascript" src="webscripts/run_scripts.js"></script>
<script type="text/javascript" src="webscripts/library.js"></script>  
</html>

library.ts:

export function appearSomeTestingSentence()  {
    document.write('111111');
};

library.js:

  "use strict";
exports.__esModule = true;
exports.appearSomeTestingSentence = void 0;
exports.appearSomeTestingSentence = function () {
    document.write('111111');
};

run_scripts.ts:

import {appearSomeTestingSentence} from './library.js';
appearSomeTestingSentence();

run_scripts.js:

"use strict";
exports.__esModule = true;
var library_1 = require("./library");
library_1.appearSomeTestingSentence();

解决方法

最后我将其整理出来。在使用tsc进行编译之前,我必须删除* .js文件,并且必须在tsconfig中进行更改后重新启动tsc。解决问题后 在tsconfig文件中将模块更改为"module" : "ESNext"

感谢您的帮助,特别感谢加-1的人。 祝贺stacoverflow社区。​​ p>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。