【react】tsx文件中的Module 'xxxx' has no default export

淩亂°似流年 2022-02-24 08:40 1136阅读 0赞

项目使用create-react-app创建,然后引入antd-mobile里面的组件报错。

报错:
在这里插入图片描述
在tsx引入react的时候报错,是通过将import React from "react" 改为import * as React from "react"去掉错误。

但是我们引入antd-mobile三方库这样就不行了。

我们需要在tsconfig.json里面加上配置:

  1. "allowSyntheticDefaultImports": true

原po: https://github.com/Microsoft/TypeScript-React-Starter/issues/8#issuecomment-301265017


然后再tsx引入scss文件报错,cannot find module。

这时候需要我们在项目根目录添加一个名为: global.d.ts的文件

内容为:

  1. declare module '*.scss' {
  2. const content: { [className: string]: string};
  3. export = content;
  4. }

原po:

https://stackoverflow.com/questions/51038522/how-to-import-scss-file-as-variable-in-react-with-typescript

发表评论

表情:
评论列表 (有 0 条评论,1136人围观)

还没有评论,来说两句吧...

相关阅读