我有一个非常简单的反应材料-ui项目。
最近,我向顶层文件夹添加了一个jsconfig.json。
{
"compilerOptions": {
"target": "es6",
"checkJs": true,
"jsx": "react"
},
"exclude": [
"node_modules",
"data",
"docs",
".cache",
"dist"
]
}效果很好。但是,VSCode发现了一些我想要删除的错误:
无法找到模块“@material ui/core/Button”。 无法找到模块“@material ui/core/styles”。 找不到模块‘容易-农民’。
进口产品运行良好,但我不愿仅仅禁用The。所有这些导入都在./节点-模块树中(包括轻松-农民)。
(顺便说一句,代码都是JavaScript,而不是TS)。
import { action, createStore, StoreProvider, useStore, useActions, thunk } from 'easy-peasy';
import Button from '@material-ui/core/Button';
import { withStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import TextField from '@material-ui/core/TextField';发布于 2019-06-26 07:45:44
您可能需要设置"module": "commonjs"
我就是这样做的:
jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"target": "es6",
"module": "commonjs",
"paths": {
"@components/*": ["./src/components/*"],
"@constants/*": ["./src/constants/*"],
"@helpers/*": ["./src/helpers/*"]
}
},
"include": [
"src/**/*"
]看看我在关于Github的问题上得到的答案
是的,如果您从
node_modules导入模块,通常需要设置"module": "commonjs"(我认为"moduleResolution": "node"也应该工作)。commonjs是默认设置,但"target": "es6"重写它以使用"module": "es6",除非您显式地指定另一个"module"设置。 模块选项在这里有更详细的介绍:理解tsconfig中的“目标”和“模块”
https://stackoverflow.com/questions/56586704
复制相似问题