Skip to content

Commit c2b2164

Browse files
authoredFeb 28, 2021
fix(compiler): return original file content and show warning on emit skip (#2410)
Closes #2407
1 parent 064bf3a commit c2b2164

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎src/compiler/ts-compiler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ export class TsCompiler implements TsCompilerInstance {
262262
this._doTypeChecking(fileName)
263263
/* istanbul ignore next (this should never happen but is kept for security) */
264264
if (output.emitSkipped) {
265-
throw new Error(interpolate(Errors.CannotCompile, { file: fileName }))
265+
this._logger.warn(interpolate(Errors.CannotProcessFile, { file: fileName }))
266+
267+
return fileContent
266268
}
267269
// Throw an error when requiring `.d.ts` files.
268270
if (!output.outputFiles.length) {

‎src/utils/messages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const enum Errors {
1717
GotUnknownFileTypeWithBabel = 'Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files.',
1818
ConfigNoModuleInterop = 'If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.',
1919
MismatchNodeTargetMapping = 'There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping',
20-
CannotCompile = "Unable to process '{{file}}'. Please make sure that `outDir` in your tsconfig is neither `''` or `'.'`.",
20+
CannotProcessFile = "Unable to process '{{file}}', falling back to original file content. Please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to ignore {{file}} from transformation",
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)
Please sign in to comment.