将模块导入项目的问题react / typescript

时间:2018-10-26 12:58:29

标签: reactjs typescript create-react-app

将模块导入到从 create-react-app

创建的React项目中时遇到问题

例如,我在src / components目录中有一个名为 uiInteraction.tsx 的文件,我想将导入到src目录中的App.js 中< / p>

我使用以下语法将其导入:

  

从'./components/uiInteraction'导入UIInteraction;

但是当我这样做时:

  

npm启动或纱线启动

我遇到以下错误:

  

未找到模块:无法解析'./components/uiInteraction'

我与:

  • 节点8.12.0

  • npm 6.4.1

  • 纱线1.10.1

  • 反应16.6.0

这是我的package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^3.3.1",
    "react": "^16.6.0",
    "react-dom": "^16.6.0",
    "react-scripts": "2.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

预先感谢您的帮助。

0 个答案:

没有答案