【发布时间】:2020-02-17 19:13:24
【问题描述】:
我正在处理一个大型 React + TypeScript 项目。
它在其他同事的本地机器上运行良好,但在我的机器上我收到以下错误:
Line 1: Parsing error: Unexpected token, expected ";"
如下所示:
这里是源代码:
export type LoadOfferType = typeof import("../offers/defaultOffer");
export const loadOffer = async (): Promise<LoadOfferType> => {
const offerName = process.env.NODE_ENV === "development" ? process.env.REACT_APP_FALLBACK_SITE : "defaultOffer";
/**
* We use a switch statement instead of ane xpression for the offer path
* because Webpack throws a critical dependency error when using paths
* that are not explicitly defined.
*/
switch (offerName) {
case "mysite.com":
return await import("../offers/mysite.com");
default:
return await import("../offers/defaultOffer");
}
};
克隆存储库后我运行的命令是:
$ yarn install
$ yarn start
这里有一些关于我的系统的信息:
$ node -v
v12.13.0
$ npm -v
6.12.0
$ yarn -v
1.19.1
知道如何解决这个问题吗?
谢谢!
【问题讨论】:
-
可以粘贴
"../offer/defaultOffer"的内容吗? -
为什么要使用动态导入,因为它位于文件的顶部并且似乎总是会被加载?为什么不
export type LoadOfferType = typeof require("../offers/defaultOffer");? -
也有可能你没有使用正确的 TypeScript 版本。在 v2.4 中添加了动态导入
-
你需要在你的配置中有
"module": "esnext"
标签: javascript reactjs typescript tslint