javascript - React - 模块解析失败:意外令牌 (5:10)
问题描述
我有一个文件 - deps.ts
:
export class Deps {
private static deps = new Map<any, any>();
public static get<T>(type: any): T {
return this.deps.get(type)
?? this.add(type, new type());
}
public static add<T>(type: any, instance: T): T {
return this.deps
.set(type, instance)
.get(type);
}
}
这是其他 TypeScript 项目中的有效源代码,但在 React 中不是。
我收到此错误:
../utils/src/deps.ts 5:10
Module parse failed: Unexpected token (5:10)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
You may need an additional loader to handle the result of these loaders.
|
| export class Deps {
> private static deps = new Map<any, any>();
|
| public static get<T>(type: any): T {
当我改变时tsconfig.json
,似乎什么都没有发生。它是create-react-app
使用 TypeScript 模板制作的,不会被弹出。
版本:
- 打字稿 4.3.5
- 节点 v14.17.2
源代码:https ://github.com/codea-live/dclone
该website/src/utils
文件夹是指向 的符号链接utils
,其中包含deps.ts
.
我将如何修复这个错误,或者让 React 忽略utils
文件夹中的错误?
解决方案
推荐阅读
- vb.net - 带有表单控制值的 VB POST 请求
- spring-batch - spring-batch 作业监控和重启
- python - 从数组列表创建数据框(不同的形状)
- c++ - 将具有任意数量参数的任何类成员函数传递给类外的函数
- flutter - Android 交易未显示在收入信息仪表板中
- php - 文档末尾的额外内容 XML PHP RSS
- r - 如何在ggplot网格中添加表格
- homebrew - 如何 brew install --cask itch.app 到 /Applications
- python - 将表情符号解析为单词 nlp
- angular - 在 Nativescript + Angular App 中以编程方式设置 ListPicker.selectedIndex