This repository was archived by the owner on Aug 7, 2021. It is now read-only.
fix: handle correctly webpack compilation errorrs #1051
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Webpack doesn't notify NativeScript CLI when there is a compilation error. So, NativeScript CLI build the app, install it on device and start it. In most cases the application crashes runtime as the webpack compilcation is not successful. Most probably there would be a red/yellow message in the console printed during the compilation. The users don't see the error message as there is too much log outputed in the console. They don't understand the exact reason why their app crashes runtime.
Webpack has a mechanism to skip the emitting phase whenever there are errors while compiling. This can be achieved using
optimization.noEmitOnErrors
property as it is described here. This PR addsnoEmitOnErrors
property in all webpack.config files:noEmitOnError
property fromtsconfig.json
forangular
andtypescript
projectstrue
forjavascript
andvue
projects.Also this PR fixes the following problems:
Currently
ts-loader
is started intranspileOnly
mode and webpack plugin (ForkTsCheckerWebpackPlugin
) runs TypeScript type checker on a separate process in order to report for compilation errors. By default the plugin only checks for semantic errors and adds them tocompilation.errors
as can be seen here. On the other side, webpack relies on compilation.errors array when deciding if should skip emitting phase. However,ts-loader
used intranspileOnly
mode still reports syntactic errors but adds them tocompilation.warnings
. This is a problem, as actually the compilation is not stopped when there is a syntactic error. SettingcheckSyntacticErrors: true
will ensure thatForkTsCheckerWebpackPlugin
will check for both syntactic and semantic errors and after that will be added tocompilation.errors
.noEmitOnError
fromtsconfig.json
when compilingts
projectsThe problem is in
ForkTsCheckerWebpackPlugin
and in the way it is integrated with webpack hooks - TypeStrong/fork-ts-checker-webpack-plugin#337.The
hmr
generates new hot-update files on every change and the hash of the next hmr update is written inside hot-update.json file. Although webpack doesn't emit any files, hmr hash is still generated. The hash is generated per compilation no matter if files will be emitted or not. This way, the first successful compilation after fixing the compilation error generates a hash that is not the same as the one expected in the latest emitted hot-update.json file. As a result, the hmr chain is broken and the changes are not applied.Rel to: NativeScript/nativescript-cli#3785
PR Checklist
What is the current behavior?
What is the new behavior?
Fixes/Implements/Closes #[Issue Number].