Search code examples
node.jstypescriptnpmtsc

TypeScript OutDir contains package.json


I'm trying to build my simple npm package, and all is well. However when I'm trying to build it it goes a bit wrong.

I get the following:

 - dist
   - package.json
   - src
      - index.js
      - index.d.ts
      - ...

But this is not what I expected to get, I'm pretty sure I've done this before and gotten, the following:

 - dist
   - index.js
   - index.d.ts
   - ...

This is what I want to end up with, but so far nothing has worked.

My tsconfig.json looks like this:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "lib": ["es6", "dom"],
        "resolveJsonModule": true,
        "declaration": true,
        "declarationMap": true,
        "sourceMap": true,
        "outDir": "dist",
        "strict": true,
        "esModuleInterop": true
    },
    "include": ["src"],
    "exclude": ["node_modules", "build", "dist"]
}

I haven't been able to find a reason for it to include the package.json or the src path. I'm using typescript@3.6.4.


Solution

  • Are you importing your package.json anywhere in your code? If you are, it's getting copied because of resolveJsonModule.

    If you want to read JSON files without them being copied over, you can do a readFile and JSON.parse.