将 JavaScript 文件导入到另一个 JavaScript 文件中,该文件被导入到另一个文件中

Import a JavaScript file into another JavaScript file that is imported into another file

我需要导入一个文件,该文件从另一个文件导入代码,然后将该文件导入到最终文件中,该文件将代码添加到 HTML 按钮。我怎样才能做到这一点?当我尝试使用下面的示例时,没有代码运行。

// file 1
export function someFunction() {
    // more code
}

// file 2
import {someFunction} from './file1';
export function otherFunction() {
    someFunction();
    // more code
}

// file 3
import {otherFunction} from './file2';
document.getElementById('some-button').onclick = otherFunction;

// in index.html 
<script type='module' src='./file3.js'></script>

解决方案是将所有文件都包含在 index.html 中作为 type="module"

<script type='module' src='./file1.js'></script>
<script type='module' src='./file2.js'></script>
<script type='module' src='./file3.js'></script>