awesome-typescript-loader icon indicating copy to clipboard operation
awesome-typescript-loader copied to clipboard

Missing declaration files

Open donaldpipowitch opened this issue 7 years ago • 8 comments

Given the following project:

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "webpack",
    "build2": "tsc --declaration --outDir dist"
  },
  "devDependencies": {
    "awesome-typescript-loader": "^3.1.2",
    "typescript": "^2.2.2",
    "webpack": "^2.3.3"
  }
}

tsconfig.json:

{
    "compilerOptions": {
      "target": "es6",
      "moduleResolution": "node",
      "declaration": true,
      "outDir": "dist"
    },
    "exclude": [
      "node_modules",
      "dist"
    ]
}

webpack.config.js:

var path = require('path');

module.exports = {
  entry: './src/index.ts',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx']
  },
  devtool: 'source-map',
  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: 'awesome-typescript-loader'
      }
    ]
  }
};

src/index.ts:

import { Foo } from './some-interface';
export {Foo};
export function foo(a: Foo) {
  return 1;
}

src/some-interface.ts:

export interface Foo {
  bar: string;
}

And running $ npm run build the generated dist/ directory misses declarations for src/some-interface.ts resulting in an invalid declaration for dist/index.d.ts, because it can't import 'Foo'.

The problems seems to be that src/some-interface.ts only contains non-JS code (just an interface). If I would export a function there and use that function in src/index.ts a dist/some-interface.d.ts would be generated.

donaldpipowitch avatar Apr 07 '17 08:04 donaldpipowitch

Just for the record, using ts-loader instead of awesome-typescript-loader currently solves the issue.

starovoitovs avatar Apr 12 '17 12:04 starovoitovs

Tried to debug it, but didn't come far. src/some-interface.ts is correctly added to the dependencies here. It looks like normally the loader should be called again with files added as dependencies here, but this isn't the case for src/some-interface.ts.

donaldpipowitch avatar Apr 17 '17 12:04 donaldpipowitch

I also had missing declaration files, with no error message when running $ npm run dev.

Running $ tsc showed the error: TS4025: Exported variable '...' has or is using private name '...'. Changing the private variable to public by exporting it fixed the problem.

robinspark avatar Apr 28 '17 05:04 robinspark

I also had missing declaration files, with no error message when running $ npm run dev.

Running $ tsc showed the error: TS4025: Exported variable '...' has or is using private name '...'. Changing the private variable to public by exporting it fixed the problem.

@robinspark My guess is that you generated the declaration files when you ran tsc. If you delete your dist folder and try to build again via webpack (this time without manually running tsc), then my guess is that the problem will come back.

adamdoyle avatar Oct 17 '18 17:10 adamdoyle

@donaldpipowitch Did you ever have any luck resolving this? I'm having the same issue with awesome-typescript-loader, and this issue if I try to switch back to vanilla ts-loader.

adamdoyle avatar Oct 17 '18 17:10 adamdoyle

I switched to ts-loader and never looked into this issue again. Sorry :(

donaldpipowitch avatar Oct 17 '18 20:10 donaldpipowitch

Hello there, any update on this?

lsagetlethias avatar Sep 12 '19 16:09 lsagetlethias

Facing the same issue:

export type datatype = {
  foo: string;
  bar: number;
};

Using ts-loader resolved this issue, but are there any other alternatives until this is fixed. We are too dependent on awesome-typescript-loader at this point.

shravyb avatar Oct 10 '19 01:10 shravyb