NativeScript: [NS8][Webpack5] Wrong bundling in release build
Environment
- CLI: 8.0.1
- Cross-platform modules: 8.0.3
- Android Runtime: 8.0.0
- Webpack: 5.0.0-beta.9
- Plugin: @nativescript-community/ui-material-button
Describe the bug
In release build on app launch I geting error ReferenceError: androidElevationProperty is not defined. I looked at the vendor.js and there really was no declaration of this variable. On debug build it works fine and vendor.js has implementation of this properties. In NS7 there is no such problem.
To Reproduce
ns create demo --ts --vue
ns plugin add @nativescript-community/ui-material-button
*importing plugin*
ns build android --release ...
Stack trace
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function
ReferenceError: androidElevationProperty is not defined
File: (file:///data/user/0/***/files/app/vendor.js:2:17209)
StackTrace:
5055(file:///data/user/0/***/files/app/vendor.js:2:17210)
at __webpack_require__(file:///data/user/0/***/files/app/bundle.js:1:112605)
at 2670(file:///data/user/0/***/files/app/vendor.js:2:414)
at __webpack_require__(file:///data/user/0/***/files/app/bundle.js:1:112605)
at 5865(file:///data/user/0/***/files/app/bundle.js:1:111613)
at __webpack_require__(file:///data/user/0/***/files/app/bundle.js:1:112605)
at (file:///data/user/0/***/files/app/bundle.js:1:112814)
at __webpack_require__.O(file:///data/user/0/***/files/app/bundle.js:1:113304)
at __webpack_require__.x(file:///data/user/0/***/files/app/bundle.js:1:113004)
at __webpack_require__.x(file:///data/user/0/***/files/app/bundle.js:1:114554)
at (file:///data/user/0/***/files/app/bundle.js:1:114585)
at (file:///data/user/0/***/files/app/bundle.js:1:114688)
at require(:1:266)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 15 (11 by maintainers)
Still looking into the details, but a workaround is to disable webpack’s export tracking with
What’s happening is that (in this particular case) the class in
ui-material-core:https://github.com/nativescript-community/ui-material-components/blob/e0fbd59f678a23214958d5895e3185e6a6241cba/src/core/index.android.ts#L286-L295
is detected as unused in the app (since it’s not exported, and the
installMixins/overrideViewBasefunctions are not called) - however webpack doesn’t drop it from thevendorchunk - and it’s definition stays as-is. The imports for those 2 properties aren’t converted to proper webpack imports either, so we end up withundefined.setNativethat crashes…vendor.jsends up looking like this:If we opt-out of the used exports tracking, webpack processes it correctly:
(
style_propertiesis defined)I actually believe this is a webpack5 bug, will need to try and reproduce it outside of NS to submit a bug report.
@tinybigideas @PackagedCat in meantime while we are implementing a fix in webpack for this case, you can do this:
Delete
webpack.config.jsns cleannpm install --legacy-peer-deps(This will generate a fresh webpack.config.js)Install sass if using .scss files in project:
npm install sass -D --legacy-peer-depsIf using Vue, be sure to install the following:
npm install vue-loader @babel/core @babel/preset-env babel-loader -D --legacy-peer-depsYou may also want to add
'__DEV__': !production,tonew webpack.DefinePlugin({section – the sample app provided used that.In
package.json, change to"main": "app.js"(or if using Angular or any other with a main bootstrap file, change to"main": "main.js")Run app and confirm runs just the same. Now make the release build.
We’ll close this issue once we have the webpack5 fix out.
This has been fixed in webpack 5.40.0 https://github.com/webpack/webpack/releases/tag/v5.40.0
https://github.com/webpack/webpack/issues/13575 https://github.com/webpack/webpack/pull/13590
Also suffering with this issue. Is there a way to hack around this issue for the time being?
Here is a demo example where the error occurs.
demo.crash.zip
The build command:
ns build android --release --key-store-path *keystore* --key-store-password *keypassword* --key-store-alias *alias* --key-store-alias-password *password*