typescript - TS2306 不是打字稿文件上的模块错误
问题描述
所以我的打字稿文件出现了这个错误。我不明白为什么它不起作用。据我了解,这是导出课程所需要做的。但是我不断收到错误消息,指出我的文件不是模块并且无法导入。
错误
TS2306 不是打字稿文件上的模块错误
export default class GridApi{
Hello(): string {
return "Hello"
}
}
这也是我的 tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"jsx": "react"
},
"exclude": [
"node_modules",
"./node_modules",
"./node_modules/*"
]
}
解决方案
您的module
设置设置为CommonJS
,这不是您想要的。CommonJS 模块使用require
语法,但您使用import/export
. 您应该改用ES6
模块:
"module": "ES6",
推荐阅读
- teradata - 如何使用遍历不同表的 Where 子句查询表?
- amazon-web-services - 如何引导 AWS Lambda 或任何其他 FAAS
- oracle - 如何增加 Oracle SQL Developer 18.1 的 GUI/字体/所有内容的大小
- python - 检查字典的变化
- python-3.x - 无法通过 Python 脚本在文本文件中写入数据
- git - 同步连接到两个远程服务器的两个本地 git 存储库
- vba - 是否有“释放”引用的 VBA 方法也会立即删除 ldb(锁定文件)?
- jquery - 传递参数的最佳方式(非常简单的 jquery/html)
- css - 媒体查询未应用于任何屏幕尺寸
- javascript - GS 中的输出准确,但在复制粘贴到任何文本编辑器时会在输出中添加多个引号