转备https://www.5axxw.com/questions/content/lzqsqm
我的文件打错了。我不明白为什么它不起作用。据我所知,这是导出类所需的操作。但我一直收到一个错误,我的文件不是一个模块,无法导入。
- export default class GridApi{
- Hello(): string {
- return "Hello"
- }
- }
这也是我的配置
- {
- "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",