我有一个 Lerna 项目,其中包含两个 Typescript 包 A 和 B。这tsconfig.json
两个包都是:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"esModuleInterop": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"allowJs": false,
"resolveJsonModule": true,
"declaration": true,
"moduleResolution": "node",
"lib": ["es2015", "dom"]
},
"include": [
"src",
"test"
],
"exclude": [
"node_modules/**",
"packages/*/node_modules/**",
"examples/*/node_modules/**",
"**/*.d.ts"
]
}
包 A 包含以下代码:
const data = require('./myData.json');
包 B 依赖于包 A。在包 B 中调用了包 A 导出的函数,因此加载了上述代码。但是,我Error: Cannot find module './myData.json'
在这种情况下。现在,查看包 AI 的编译器输出目录,看不到 JSON 文件。事实上,node_modules
在包 AI 中查看包 B 的目录也看不到该文件。
为什么 JSON 文件可能会从已发布的包中丢失?在 Typescript 包中包含资源文件(JSON、纯文本)需要做些什么特别的事情吗?