0

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?

Boon
  • 1,073
  • 1
  • 16
  • 42
  • 3
    As far as I know, `tsc` has no option to copy resource files; you'll need to use a separate tool. I'll leave the question unanswered to encourage people to suggest their favorite tools/approaches. – Matt McCutchen Aug 31 '18 at 22:05
  • Thanks! I did not realize this. This link seems relevant to your answer: https://stackoverflow.com/questions/38708200/angular-2-typescript-compiler-copy-html-and-css-files – Boon Sep 03 '18 at 08:58

0 Answers0