reactjs - 出现错误:“当提供 '--isolatedModules' 标志时,所有文件都必须是模块”在 React with TypeScript 中
问题描述
我似乎无法摆脱这个错误。我正在使用带有 TypeScript 的 create-react-app。任何帮助,不胜感激。谢谢。
All files must be modules when the '--isolatedModules' flag is provided. TS1208
> 1 | import randomcolor from 'randomcolor';
| ^
2 | import React from 'react';
3 | import tasksData from '../../assets/data/tasksData';
4 | import { Task } from '../../model/task';
这些是我的 tsconfig 文件。我创建了一个基本文件,因为原始 tsconfig 文件被反应构建脚本覆盖。
tsconfig.base.json
{
"compilerOptions": {
"isolatedModules": false
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
],
"exclude": [
"node_modules"
],
"extends": "./tsconfig.base.json"
}
解决方案
未使用的文件.ts
或.tsx
文件可能会出现此错误。我有没有使用的空.ts
文件,所以只需要删除未使用的文件。
删除了未使用的文件/example/index.ts
推荐阅读
- java - 休眠链接到对象中的下一个和/或上一个
- reactjs - 是的,对具有相同名称的动态表单进行验证
- reader - 如何从 Utf8JsonReader 获取完整的 JSON 字符串?
- go - 无法命名包“文档”
- c - getopt 忽略命令行参数
- javascript - 什么是“导入为”?
- python - while 循环在列表达到一定长度后中断
- anaconda - Anaconda-navigator 有许多未知的奇怪绿色圆圈
- c - 排序结构
- python - 你如何修复 numpy 和 pandas 的“runtimeError: package failed to pass a sanity check”?