当我跑步时
bun run index.ts
我收到一个错误:
npm run start
Debugger attached.
> [email protected] start
> bun run index.ts
11 | dialogCallback;
12 | static PAGE_LOADED = "DOMContentLoaded";
13 | constructor() {
14 | }
15 | static startWhenReady(ClassReference, startWith) {
16 | window.addEventListener(BaseClass.PAGE_LOADED, (event) => {
^
ReferenceError: Can't find variable: window
at startWhenReady (BaseClass.js:16:9)
at index.ts:12:11
我需要进口什么吗?或者以某种方式告诉Bun这将在浏览器中运行?
如果我构建
index.ts
使用TypeScript,我不会出现任何错误。这是我的
tsconfig.json
:
{
"compilerOptions": {
"target": "ESNext",
"module": "Preserve",
"inlineSourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"allowUnreachableCode": true,
"skipLibCheck": true
}
}
我已经尝试将web库添加到其中,但仍然会出现错误
bun-run index.ts
.
{
"compilerOptions": {
"target": "ESNext",
"module": "Preserve",
"inlineSourceMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2022", "dom", "dom.iterable"],
/* Type Checking */
"strict": true,
"noImplicitOverride": true,
"allowUnreachableCode": true,
"skipLibCheck": true
}
}
index.ts
:
import {BaseClass} from "base-class-ts/BaseClass"
export class MyClass extends BaseClass {
constructor() {
super();
console.log("Hello world ...")
}
}
BaseClass.startWhenReady(MyClass);
我一直在打电话
bun run start
现在我想应该是,
bun bun.build.js
。这将指向我的配置文件。