Ts-loader: Can't import plain d.ts files when transpileOnly=true

Created on 5 Sep 2016  路  19Comments  路  Source: TypeStrong/ts-loader

This is actually the exact same issue as I have with awesome-typescript-loader: https://github.com/s-panferov/awesome-typescript-loader/issues/225:

I have a shared module for shared interfaces between my server and my client. It contains several d.ts files with interfaces I share between my server and the UI. When I use ts-loader everything works as expected, when I use this ts-loader with transpileOnly=true I get:

ERROR in ./src/component.ts
Module not found: Error: Cannot resolve module 'shared/data' in ...src/component
 @ ./src/component.ts 12:26-73

The shared/data should be shared/data.d.ts but it doen't find it. If I add the d.ts explicitly I get this error:

ERROR in ./~/shared/data.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed
    at Object.assert (node_modules\typescript\lib\typescript.js:2099:23)
    at Object.transpileModule (node_modules\typescript\lib\typescript.js:53173:18)
    at Object.loader (node_modules\ts-loader\index.js:421:49)
 @ ./src/component.ts 12:31-83

configuration:

'ts-loader?' + JSON.stringify({
                        transpileOnly: true,
                        configFileName: 'tsconfig.webpack.json'
                    })

config file:

{
    "compilerOptions": {
        "isolatedModules": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "es6",
        "moduleResolution": "node",
        "noImplicitAny": false,
        "sourceMap": true,
        "target": "es5"
   },
   "files": ["src/component"]
}

_Not critical_ workaround is to just change the files to ts files and transpile them to empty js files.

wontfix

Most helpful comment

Wow, is this for real? yes it is. holy crap. totally wasted 4 hours on that. this is only clue that comes up on Google after 4 hours of banging on it with a hammer.

All 19 comments

Is there any solution for this?

Wow, is this for real? yes it is. holy crap. totally wasted 4 hours on that. this is only clue that comes up on Google after 4 hours of banging on it with a hammer.

Yeah, actually it is real. And I don't know a proper workaround. How do projects with external libraries like angular work in transpileOnly mode? I mean it is obviously not feasible to convert their typings into normal .ts files.

How are you importing the module?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Closing as stale. Please reopen if you'd like to work on this further.

ARRRGH! How do I fix this? All I've done is this:

  1. Create a default vue app using Typescript.
  2. Generate protobuf Typescript files.
  3. Try to import them like this:

    import {Memory} from './foo_pb';

The file ./foo_pb.d.ts exists god damn it but it still says it cannot resolve it.

Sorry for being a bit pissed off but this is surely a basic thing that should work, and I've been trying to solve it all day.

Renaming to foo_pb.ts does not work because then it gives a load of errors about the functions not having definitions (fair enough - they are in memory.js).

Please reopen this.

Reopened. I'm not working on this, but if you'd like to have a crack at it and raise a prospective pr I'd be happy to support you

Actually I think I was looking in the wrong place for the problem. I was using some files generated by protoc, and due to a stupid design it was possible to give it "unsupported" options, and it would silently ignore them and only generate some files. It should have generated foo_pb.d.ts and foo_pb.js, but it wasn't generating the latter file. With that file present the import works (and I do have transpileOnly=true).

So maybe it was working as intended all along. Sorry!!

Hi everyone,
do we have any idea how to fix this?
renaming to .ts works but feels wrong :(

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

still relevant 馃槩

I'm afraid I can't spend any time looking into this directly, but if you'd like to I'd appreciate it and I'll help when I can

Same

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Closing as stale. Please reopen if you'd like to work on this further.

still relevant

I encountered the same issue.
It's because there is another loader in my webpack config file and it calls ts-loader without setting transpileOnly to true.

Same issue, any advice?

Was this page helpful?
0 / 5 - 0 ratings