我正在尝试做一些与文档中的 jquery 路径示例 非常相似的事情,但是 TS 不断抛出 TS2307
(webpack 编译良好):
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@client": [
"client",
],
"@suir": [
"../node_modules/semantic-ui-react/dist/commonjs", // not working
],
},
// …
},
"include": [
"*.d.ts",
"client/**/*",
"../node_modules/semantic-ui-react", // is this necessary?
],
Changing baseUrl
to "."
and updating includes
and paths
makes no difference ( @client
continues to work and @suir
继续不起作用)。
将 "@suir"
更改为 "@suir/"
或 "@suir/*"
(并附加 /*
值也没有区别。
我这样做的原因是为了简化我的导入(我明确指定它们而不是从包中提取命名导出以减少我的供应商包大小 - 节省大约 1 MB):
import Button from 'semantic-ui-react/dist/commonjs/elements/Button'; // works
import Button from '@suir/elements/Button'; // not found
原文由 Jakob Jingleheimer 发布,翻译遵循 CC BY-SA 4.0 许可协议
我不知道为什么这在我第 11 次尝试(但不是第 10 次)中起作用,但
/*
似乎是秘诀,文档中的示例显然是指向到特定文件(并且省略了文件扩展名)。