awesome-typescript-loader
awesome-typescript-loader copied to clipboard
Missing declaration files
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.
Just for the record, using ts-loader instead of awesome-typescript-loader currently solves the issue.
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
.
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.
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.
@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.
I switched to ts-loader and never looked into this issue again. Sorry :(
Hello there, any update on this?
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.