javascript - 我无法在 React / Typescript 上将图像导入我的模块,只需要作品
问题描述
这在 UI 级别上没有问题:
import profileImg from '../../assets/murdoch.jpg';
但是我在 VSCode 上收到此错误:
找不到模块'../../assets/murdoch.jpg'.ts(2307)
这在 UI 和 VSCode 上都没有问题:
const profileImg = require('../../assets/murdoch.jpg');
但我想导入它,因为测试没有通过
SyntaxError: Invalid or unexpected token
3 | import ProfilePicture from './ProfilePicture';
4 |
> 5 | const profileImg = require('../../assets/murdoch.jpg');
这是我的tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"removeComments": true,
"baseUrl": "./",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": false,
"jsx": "react",
"lib": ["es6", "dom"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": ["node_modules", "jest.config.js", "webpack.config.js"]
}
我错过了什么?
编辑:
项目树
解决方案
推荐阅读
- go - go-containerregistry 包列出了来自所有项目/组织的 GCR 存储库
- ruby-on-rails - 在 Ruby 中从 .map 中排除数据
- python - 使用 Windows 终端而不是命令提示符运行 python.exe
- java - 在 CompletableFuture 的 whenComplete() 之前返回的方法
- javascript - 我需要通过按下 Javascript 中的按钮来修改和更新值
- parameters - 在报表生成器中,如何将值列表传递给参数,以便允许多个值或空值?
- python - 熊猫中的 PanelOLS 替代品
- python - 如何单击按钮并使用 selenium 移至下一页?
- r - 如何使用 dplyr 包和排列命令在 R 中按特定顺序对行进行排序
- android - 移动应用程序 - Twilio 视频/呼叫不一致的推送通知