Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

declaration:true in tsconfig causes error #45

Closed
flyon opened this issue Sep 18, 2015 · 6 comments
Closed

declaration:true in tsconfig causes error #45

flyon opened this issue Sep 18, 2015 · 6 comments
Labels

Comments

@flyon
Copy link

flyon commented Sep 18, 2015

Hey, I would like to get a .d.ts output besides the usual bundle, So I'm trying to add this line to tsconfig.json:

declaration: true

But when I do that I get this error:

ERROR in ./init.ts Module parse failed: F:\wamp\www\davine\sites\terramaya.org\ts\trm\node_modules\ts-loader\index.j s!F:\wamp\www\davine\sites\terramaya.org\ts\trm\node_modules\ts-jsx-loader\index.js!F:\wamp\www\d avine\sites\terramaya.org\ts\trm\init.ts Line 1: Unexpected token : You may need an appropriate loader to handle this file type. | {"version":3,"file":"init.js","sourceRoot":"","sources":["init.ts"],"names":[],"mappings":"AAAA ;;GAEG;AACH,sCAAsC;.....

If I remove the declaration line from tsconfig.json it works fine.
Full tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "out": "../../public_html/js/builds/trm.main.js",
    "sourceMap": true,
    "declaration":true
  },
  "files": [
    "init.ts"
  ]
}

Full webpack.config.js:

// webpack.config.js
var webpack = require('webpack');

module.exports = {
    entry: './init.ts',
    output: {
        filename: '../../public_html/js/builds/trm.main.js'
    },
    resolve: {
        extensions: ['', '.ts', '.webpack.js', '.web.js', '.js']
    },
    module: {
        loaders: [
            { test: /\.ts$/, loader: 'ts-loader!ts-jsx-loader' }
        ]
    },
    cache:false,
    watch:true,
    plugins: [
        new webpack.SourceMapDevToolPlugin(
            '[file].map', null,
            "../../../ts/trm/[resource-path]", "../../../ts/trm/[resource-path]")
    ]
};

Is it possible to get a declaration output file?

@jbrantly
Copy link
Member

It seems like there are two issues at play here.

  1. The loader is erroring when declaration: true is specified. This is clearly a bug and needs to be fixed.
  2. You want to be able to somehow emit generated .d.ts files. Since webpack primarily deals with generating bundles, how do you envision this working? It would probably be somewhat simple to output .d.ts files next to corresponding .ts files (basically the equivalent of what --declaration does), but is that what you're looking for? Or are you instead looking for something more advanced like what dts-bundle or dts-generator do? See also Generate a single declaration file for external modules microsoft/TypeScript#2568

@jbrantly jbrantly added the bug label Sep 18, 2015
@flyon
Copy link
Author

flyon commented Sep 18, 2015

yes one .d.ts file for the generated bundle is exactly what I would want. I see now... that this is not trivial. To bad there is no webpack solution yet!... as I just switched from grunt to webpack :)

Tnx for the links, I'll try one of those

@flyon flyon closed this as completed Sep 18, 2015
@jbrantly
Copy link
Member

Reopening because there still is the bug to fix

@jbrantly jbrantly reopened this Sep 23, 2015
This was referenced Sep 23, 2015
@jbrantly
Copy link
Member

@flyon I was just looking into fixing this but could not duplicate. I realized that there's actually already a unit test for it since this issue was fixed in v0.5.0. Could you confirm what version of TypeScript and ts-loader you're using? Thanks!

@jbrantly
Copy link
Member

jbrantly commented Oct 3, 2015

I don't believe this is a bug anymore (as of v0.5.0). @flyon if I'm incorrect feel free to reopen. Thanks!

@jbrantly jbrantly closed this as completed Oct 3, 2015
@flyon
Copy link
Author

flyon commented Dec 13, 2015

sorry for the late reply, seems to be not an issue anymore with my current version. I do however still want to try and create a single declaration file for my bundles. It seems the module dts-bundle that you mentioned would be a good fit for now, but for that I need single .d.ts files first of all. You mentioned simple to (add support to) output these? currently adding declaration:true to tsconfig.json does nothing.

Edit: all add this request to #48 and leave this one closed

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

No branches or pull requests

2 participants