I have a Lerna project containing two Typescript packages A and B. The tsconfig.json
for both packages is:
{
"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"
]
}
Package A contains the following code:
const data = require('./myData.json');
Package B depends on package A. Inside package B a call is made to a function exported by package A, and so the above code is loaded. However, I get Error: Cannot find module './myData.json'
in this context. Now, looking inside compiler output directory for package A I do not see the JSON file. Indeed, looking inside package B's node_modules
directory at package A I do not see the file there either.
Why might the JSON file missing from the published package? Is there anything special that needs to be done to include resource files (JSON, plaintext) in the Typescript package?