【发布时间】:2020-08-18 16:17:16
【问题描述】:
我被困住了。我尝试了许多解决方案,但没有一个有效。 尝试实现一个模块,我收到以下错误消息:
未捕获的引用错误:未定义导出
我试过solution from Stack Overflow,但它不起作用。更改 tsconfing 中的任何内容都没有任何区别。我在 HTML 文件的脚本中添加了var exports = {};,错误从“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>
库.ts:
export function appearSomeTestingSentence() {
document.write('111111');
};
库.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();
【问题讨论】:
-
您声称无效的链接问题有 17 个答案。您尝试了哪个答案?您是如何实施解决方案的?他们是怎么不工作的?
-
我尝试在我的 html 文件中添加评论 ' "module": "commonjs" ' 我把: ' '。它将错误代码更改为“require”而不是“imports”。我试着改变 tsconfig 像:' { "compilerOptions": { "module": "es6", "target": "es5", } }' 没有任何效果!
-
<script type=module>不适用于 CommonJS。 -
我已经改了 Aluan Haddad,没区别
标签: javascript typescript tsc