Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Missing declaration files #411

Open
donaldpipowitch opened this issue Apr 7, 2017 · 8 comments
Open

Missing declaration files #411

donaldpipowitch opened this issue Apr 7, 2017 · 8 comments
Labels

Comments

@donaldpipowitch
Copy link

donaldpipowitch commented Apr 7, 2017

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.

@starovoitovs
Copy link

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

@donaldpipowitch
Copy link
Author

donaldpipowitch commented Apr 17, 2017

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.

@robinspark
Copy link

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.

@adamdoyle
Copy link

adamdoyle commented Oct 17, 2018

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
Copy link

adamdoyle commented Oct 17, 2018

@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.

@donaldpipowitch
Copy link
Author

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

@lsagetlethias
Copy link

Hello there, any update on this?

@shravyb
Copy link

shravyb commented Oct 10, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants