Javascript 无法从中找到模块;“未定义”;

Javascript 无法从中找到模块;“未定义”;,javascript,typescript,Javascript,Typescript,我正在尝试导入升华文本3中的外部模块。外部模块装运.ts如下所示: export interface Ship { name: string; port: string; displacement: number; } { "compileOptions": { "module": "commonjs" }, "files": [ "./Ship.ts" ] } output.ts文件包含import S

我正在尝试导入升华文本3中的外部模块。外部模块装运.ts如下所示:

export interface Ship {
    name: string;
    port: string;
    displacement: number;
}
{
    "compileOptions": {
        "module": "commonjs"
    },
    "files": [
        "./Ship.ts"
    ]
}
output.ts文件包含import Ship=require(“/Ship”)并且此文件的保存和生成无错误。tsconfig.json如下所示:

export interface Ship {
    name: string;
    port: string;
    displacement: number;
}
{
    "compileOptions": {
        "module": "commonjs"
    },
    "files": [
        "./Ship.ts"
    ]
}
但是,在查看php页面内部和索引时:

<html>
    <head>
        <script src="node_modules/commonjs-require/commonjs-require.js"></script>
        <script src="output.js"></script>
    </head>
    <body>
        Hello TypeScript
    </body>
</html>
。。。传送至:

"use strict";
function greet() {
    console.log("Hello Ship");
}
exports.greet = greet;
。。。错误消息
commonjs require.js:15未捕获错误:无法从“未定义”
中找到模块“/Ship”,但在尝试通过import Ship=require(“/Ship”)import{Ship}从“/Ship”访问模块后,该消息仍处于打开状态。

更新


还尝试将
//
//
包含在output.ts的顶部,但没有效果。

您正在导出一个不生成任何代码的接口,并且试图在运行时要求它。

是否尝试删除该接口。/?我相信它们在这个案例中是隐含的。这和崇高的文本有什么关系?请不要给你的文本编辑器添加标签,除非问题出在它身上。奥尔登。我尝试了多种组合删除隐含的/但它没有解决问题。错误消息仍在.Stijn上。看看我的更新。即使文件的内容是生成的代码,错误仍然存在。请尝试从“/Ship”(可能添加扩展名?)导入{greet}或向函数添加默认值,如export default function`我尝试了两个建议的选项。-import-选项具有相同的错误。第二个模块(adding-default-)没有通过传输,错误是模块“C:/xampp/htdocs/typescript/Ship”没有导出的成员“greet”。