在我的控制台中,我不断收到 ReferenceError: exports is not defined
错误。
代码:
应用.ts:
import {IDetails} from "./interfaces/IDetails";
class MyClass implements IDetails{
constructor(){}
public render (elem: string, text: string) {
let el: HTMLElement = document.querySelector(elem);
el.textContent = text;
el.innerText = text;
}
}
window.onload = () => {
let myClass = new MyClass();
myClass.render('body', 'Hello World!');
};
IDetails.ts:
export interface IDetails {
elem: string,
text: string
}
tsconfig.json:
{
"compilerOptions": {
"outDir": "./build/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es5",
"removeComments": true,
"allowJs": true
}
}
webpack.config.js:
module.exports = {
entry: './index.ts',
output: {
filename: 'bundle.js',
path: __dirname
},
watch: true,
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
transpileOnly: true
}
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
};
我在这里做错了什么?
编辑:我已经使用webpack.config.js
和tsconfig.json
编辑了我的问题。可能还值得注意的是,我在 Chrome 浏览器中直接从 Webstorm 查看文件。这会是个问题吗?
谢谢。
最佳答案
尝试设置 "allowJs": false
或者使用 exclude https://www.typescriptlang.org/docs/handbook/tsconfig-json.html 从 typescript 编译器中排除 webpack 配置文件
关于javascript - typescript - 引用错误 : exports is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43923497/