Skip to content

tns run android --bundle doesn't pause on webpack compilation error #3785

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

Closed
sis0k0 opened this issue Aug 1, 2018 · 7 comments
Closed

tns run android --bundle doesn't pause on webpack compilation error #3785

sis0k0 opened this issue Aug 1, 2018 · 7 comments
Assignees
Labels
bug e2e test needed Describes that issue requires functional test run Describes issues related to run command severity: high webpack
Milestone

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Aug 1, 2018

Please, provide the details below:

Tell us about the problem

When you run tns run android --bundle and the webpack compilation fails, the CLI continues with native build, installing the app, etc. It should fail instead.

Note: tns build android --bundle works correctly.

Which platform(s) does your issue occur on?

I tested it only on Android.

Please provide the following version numbers that your issue occurs with:

  • CLI: next, reproducible with 4.1.2 too
  • Cross-platform modules: next
  • Runtime(s): next
  • Plugin(s): nativescript-dev-webpack is next

Please tell us how to recreate the issue in as much detail as possible.

Using the attached project:

tns run android --bundle

Is there code involved? If so, please share the minimal amount of code needed to

The attached project has an invalid require.
jsapp.tar.gz

@cowboyd
Copy link

cowboyd commented Mar 21, 2019

This happens on ios with webpack as well. Here is a repository that reproduces the error: https://github.com/resideo-platform/exemplar/

You can introduce a syntax error into the typescript.

  1. compilation fails
  2. it goes ahead and tries to deploy the app
❯❯❯❯ yarn start ios                                                                                                                     ~/C/N/exemplar master
yarn run v1.13.0
$ tns run ios
Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.
Searching for devices...
Hot Module Replacement (HMR) is currently in Beta. For more information about the current development state and any known issues, please check the relevant GitHub issue: https://github.com/NativeScript/NativeScript/issues/6398
Hook skipped because bundling is in progress.
Running webpack for iOS...
File change detected. Starting incremental webpack compilation...

webpack is watching the files…

Hash: bd64d6d5b40ba781b911
Version: webpack 4.27.1
Time: 3370ms
Built at: 03/21/2019 2:55:18 PM
                                                                                            Asset       Size  Chunks             Chunk Names
                               App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json   2.31 KiB          [emitted]
                               App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-1024.png   98.7 KiB          [emitted]
                                 App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-20.png    1.2 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   3.61 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   6.68 KiB          [emitted]
                                 App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-29.png   1.64 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   4.73 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   9.24 KiB          [emitted]
                                 App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-40.png    2.6 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   7.59 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   14.7 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   14.7 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   31.4 KiB          [emitted]
                                 App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png   7.24 KiB          [emitted]
                              App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   22.3 KiB          [emitted]
                            App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/[email protected]   27.6 KiB          [emitted]
                                                  App_Resources/iOS/Assets.xcassets/Contents.json   62 bytes          [emitted]
                          App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Contents.json    5.1 KiB          [emitted]
                      App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-1125h.png    160 KiB          [emitted]
                    App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]   62.2 KiB          [emitted]
                    App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]    112 KiB          [emitted]
                    App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]    180 KiB          [emitted]
                App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape-X.png    165 KiB          [emitted]
               App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape-XR.png   43.2 KiB          [emitted]
           App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape-XS-Max.png   71.5 KiB          [emitted]
                  App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Landscape.png   60.9 KiB          [emitted]
               App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]    187 KiB          [emitted]
               App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]    198 KiB          [emitted]
                App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait-XR.png   43.4 KiB          [emitted]
            App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait-XS-Max.png   72.7 KiB          [emitted]
                   App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default-Portrait.png   59.5 KiB          [emitted]
                App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]    182 KiB          [emitted]
                            App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/Default.png   20.3 KiB          [emitted]
                         App_Resources/iOS/Assets.xcassets/LaunchImage.launchimage/[email protected]   61.4 KiB          [emitted]
                 App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/Contents.json  426 bytes          [emitted]
   App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/LaunchScreen-AspectFill.png   1.67 KiB          [emitted]
App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/[email protected]    3.9 KiB          [emitted]
App_Resources/iOS/Assets.xcassets/LaunchScreen.AspectFill.imageset/[email protected]   34.4 KiB          [emitted]
                     App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/Contents.json  414 bytes          [emitted]
           App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/LaunchScreen-Center.png   65.3 KiB          [emitted]
        App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/[email protected]    202 KiB          [emitted]
        App_Resources/iOS/Assets.xcassets/LaunchScreen.Center.imageset/[email protected]   91.9 KiB          [emitted]
                                                                     App_Resources/iOS/Info.plist   1.49 KiB          [emitted]
                                                        App_Resources/iOS/LaunchScreen.storyboard   4.04 KiB          [emitted]
                                                                 App_Resources/iOS/build.xcconfig  504 bytes          [emitted]
                                                                                        bundle.js   32.4 KiB  bundle  [emitted]  bundle
                                                                                     package.json   82 bytes          [emitted]
                                                                                       starter.js   39 bytes          [emitted]
                                                                                        vendor.js   1.39 MiB  vendor  [emitted]  vendor
Entrypoint bundle = vendor.js bundle.js
[./app.css] 922 bytes {bundle} [built]
[./main.ts] 926 bytes {bundle} [built]
[./package.json] 73 bytes {bundle} [optional] [built]
    + 154 hidden modules

ERROR in src/main.ts(1,6): error TS1005: ';' expected.
src/main.ts(1,20): error TS1005: '=' expected.
src/main.ts(1,23): error TS1005: ';' expected.
src/main.ts(1,38): error TS1005: ';' expected.
src/main.ts(1,41): error TS1005: ';' expected.
src/main.ts(1,46): error TS1005: ';' expected.
src/main.ts(1,51): error TS1005: ';' expected.
src/main.ts(1,60): error TS1005: ';' expected.
src/main.ts(1,75): error TS1005: ',' expected.
src/main.ts(1,83): error TS1005: ',' expected.
src/main.ts(1,87): error TS1005: ',' expected.

Webpack compilation complete. Watching for file changes.
Webpack build done!
Hook skipped because either bundling or livesync is in progress.
Preparing project...
Project successfully prepared (iOS)
Building project...
Xcode build...
Project successfully built.
Installing on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193...
Successfully installed on device with identifier '3C910396-CEB5-4E0D-A0B3-7CB9A2341193'.
Successfully transferred bundle.js on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193.
Successfully transferred package.json on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193.
Successfully transferred starter.js on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193.
Successfully transferred vendor.js on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193.
Restarting application on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193...
Successfully synced application com.resideo.exemplar on device 3C910396-CEB5-4E0D-A0B3-7CB9A2341193.
CONSOLE INFO file:///app/vendor.js:126:36: HMR: Hot Module Replacement Enabled. Waiting for signal.
CONSOLE INFO file:///app/vendor.js:126:36: HMR: Hot Module Replacement Enabled. Waiting for signal.

@rosen-vladimirov rosen-vladimirov added this to the 6.0.0 milestone May 22, 2019
@rosen-vladimirov rosen-vladimirov added the run Describes issues related to run command label May 22, 2019
@rosen-vladimirov rosen-vladimirov removed this from the 6.0.0 milestone Jul 16, 2019
@DimitarTachev DimitarTachev changed the title tns run android --bundle doesn't exit on webpack compilation error tns run android --bundle doesn't pause on webpack compilation error Aug 8, 2019
@DimitarTachev
Copy link
Contributor

DimitarTachev commented Aug 8, 2019

@sis0k0

I've updated the issue title as the CLI should pause on Webpack error instead of exiting the process. The user should be able to fix this error and the CLI should continue with a native build or a LiveSync.

@rosen-vladimirov rosen-vladimirov added this to the 6.1.1 milestone Aug 26, 2019
@KristianDD KristianDD modified the milestones: 6.1.1, 6.1.2 Sep 17, 2019
Fatme added a commit to NativeScript/nativescript-dev-webpack that referenced this issue Sep 26, 2019
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](https://webpack.js.org/configuration/optimization/#optimizationnoemitonerrors). This PR adds `noEmitOnErrors` property in all webpack.config files:
* The default value is based on `noEmitOnError` property from `tsconfig.json` for `angular` and `typescript` projects
* The default value is `true` for `javascript` and `vue` projects.

Also this PR fixes the following problems:

1. Check for syntactic errors when running webpack compilation in ts projects

Currently `ts-loader` is started in `transpileOnly` 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 to `compilation.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 in `transpileOnly` mode still reports syntactic errors but adds them to `compilation.warnings`. This is a problem, as actually the compilation is not stopped when there is a syntactic error. Setting `checkSyntacticErrors: true` will ensure that `ForkTsCheckerWebpackPlugin` will check for both syntactic and semantic errors and after that will be added to `compilation.errors`.

2. Respect `noEmitOnError` from `tsconfig.json` when compiling in `ts` projects

The problem is in `ForkTsCheckerWebpackPlugin` and in the way it is integrated with webpack hooks - TypeStrong/fork-ts-checker-webpack-plugin#337.

3. Send the hash of compilation to NativeScript CLI

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
@Fatme Fatme modified the milestones: 6.1.2, 6.2.0 Sep 26, 2019
@Fatme Fatme added the e2e test needed Describes that issue requires functional test label Sep 30, 2019
@Fatme
Copy link
Contributor

Fatme commented Sep 30, 2019

Acceptance criteria:

  • Ensure webpack compilation stops on syntactic/semantic error in angular app whennoEmitOnError is true in tsconfig.json
  • Ensure app crashes runtime on syntactic/semantic error in angular app whennoEmitOnError is false in tsconfig.json
  • Ensure webpack compilation stops on wrong import in javascript or vue app whennoEmitOnErrors is true in webpack.confg.js
  • Ensure app doesn't crash runtime on syntactic error in javascript or vue app whennoEmitOnErrors is false in webpack.confg.js
  • Ensure the new nativescript-dev-webpack plugin is backwards compatible with NativeScript CLI

known limitation:

@endarova
Copy link
Contributor

@endarova
Copy link
Contributor

@endarova
Copy link
Contributor

@Fatme
Copy link
Contributor

Fatme commented Oct 22, 2019

We have the following limitations due to the fact that errors are processed in a different manner from webpack's loaders/plugins:

  • angular doesn't report type errors while webpack is running as they started separate process for checking the errors
  • errors in .html files in angular apps are not reported to webpack
  • errors in .scss files in angular apps are reported to webpack
  • errors in .xml files are not reported to webpack
  • only Module not found error is handled by webpack in js/vue apps

Fatme added a commit to NativeScript/nativescript-dev-webpack that referenced this issue Oct 25, 2019
We have a limitation that webpack compilation doesn't stop on error in typescript applications. That was due to the issue in fork-ts-checker-webpack-plugin. After merging [the PR that fixes the issue](TypeStrong/fork-ts-checker-webpack-plugin#337) and releasing 2.0.0 version of the plugin, we can update it on our side and that way webpack compilation will stop on syntax/semantic errors within the application.

Rel to: NativeScript/nativescript-cli#3785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug e2e test needed Describes that issue requires functional test run Describes issues related to run command severity: high webpack
Projects
None yet
Development

No branches or pull requests

8 participants