Uncaught ReferenceError: exports is not defined //year 2020
Uncaught ReferenceError: exports is not defined //year 2020
我卡住了。我尝试了很多解决方案,但其中 none 有效。
尝试实现模块时,我收到此错误消息:
Uncaught ReferenceError: exports is not defined
我试过,但还是不行。更改 tsconfing 中的任何内容都没有任何区别。我将 var exports = {};
添加到 HTML 文件中的脚本中,错误从“exports”更改为“require” - 死胡同。
服务器节点:
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"
。
我卡住了。我尝试了很多解决方案,但其中 none 有效。 尝试实现模块时,我收到此错误消息:
Uncaught ReferenceError: exports is not defined
我试过var exports = {};
添加到 HTML 文件中的脚本中,错误从“exports”更改为“require” - 死胡同。
服务器节点:
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"
。