ts-loader: Can't import plain d.ts files when transpileOnly=true
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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 14
- Comments: 23 (4 by maintainers)
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.
I have found a fairly clean workaround to this problem (specifically, for getting
transpileOnly
to work with.d.ts
files underfork-ts-checker-webpack-plugin
). Any interface that you import from a.d.ts
file, useimport type
rather than plainimport
. The plugin will then parse the definition file and correctly type check against it. No more import errors!@joebnb, @LvChengbin, and @artyomtrityak, perhaps this strategy will work for you.
Special thanks to @dhoulb for getting me on the right track in this comment.
Closing as stale. Please reopen if you’d like to work on this further.
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.
You’re right about that. You ought to be able to
import type
for interfaces, and do a separateimport
for enums and such. If you’re hoping instead to import entire files, you may need to move enums to separate files. I would normally be averse to architecting around a local development plugin, but the velocity savings are huge and worth it in my opinion.