导入本地文件未解决

问题描述

(短篇小说)

我有两个打字稿文件:renderer.tsxapp.tsx

我想将后者导入前者,所以我使用:

import './app'

然而,VS Code 在抱怨(其实我猜 ESlint 在抱怨):

error in VSCode

消除此错误的先决条件是什么?

我见过语法完全相同的其他项目,没有任何问题。

(长篇故事)

我想学习如何使用 typescript 和 react 构建电子应用程序。我在电子锻造文档中找到了 this guide

遵循指南在运行时有效,但 VS Code 显示错误错误。

我做了什么:

yarn create electron-app my-app --template=typescript-webpack
cd my-app
yarn add react react-dom
yarn add --dev @types/react @types/react-dom

创建了 src/app.tsx 文件(与另一个文件在同一目录中):

import * as React from 'react';
import * as ReactDOM from 'react-dom';

function render() {
  ReactDOM.render(<h2>Hello from React!</h2>,document.body);
}

render();

并添加到 renderer.tsx 文件的最后:

import './app'

最后,在"jsx": "react"中添加了tsconfig.json

运行 yarn start 有效,应用按预期启动

效果很好,应用程序打开了。

但是 VS Code 显示了我上面提到的错误 :( (Unable to resolve path to module './app' .eslintimport/no-unresolved)

如何解决?

完整再现:https://github.com/stevebeauge/sosp-sp-tools

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)