0

Cannot build android with svelte-native on linux:

$ ns build android
Preparing project...
assets by path fonts/ 350 KiB
  asset fonts/fa-solid-900.ttf 188 KiB [compared for emit] [from: app/fonts/fa-solid-900.ttf] [copied]
  asset fonts/fa-brands-400.ttf 128 KiB [compared for emit] [from: app/fonts/fa-brands-400.ttf] [copied]
  asset fonts/fa-regular-400.ttf 33.3 KiB [compared for emit] [from: app/fonts/fa-regular-400.ttf] [copied]
  asset fonts/LICENSE.txt 1.51 KiB [compared for emit] [from: app/fonts/LICENSE.txt] [copied]
assets by path *.js 6.56 MiB
  asset vendor.js 6.19 MiB [compared for emit] (name: vendor) (id hint: defaultVendor)
  asset bundle.js 363 KiB [compared for emit] (name: bundle)
  asset runtime.js 13.8 KiB [compared for emit] (name: runtime)
Entrypoint bundle 6.56 MiB = runtime.js 13.8 KiB vendor.js 6.19 MiB bundle.js 363 KiB
runtime modules 3.05 KiB 9 modules
orphan modules 356 bytes [orphan] 6 modules
modules by path ./node_modules/ 2.33 MiB 340 modules
modules by path ./app/ 141 KiB
  modules by path ./app/components/*.svelte 18.4 KiB
    ./app/components/Home.svelte 8.7 KiB [built] [code generated]
    ./app/components/Audio.svelte 4.44 KiB [built] [code generated] [1 warning]
    ./app/components/AudioPlayer.svelte 5.22 KiB [built] [code generated]
  ./app/app.ts 382 bytes [built] [code generated]
  ./app/app.css 118 KiB [built] [code generated]
  ./app/App.svelte 3.54 KiB [built] [code generated]
  ./app/utils/AudioPlay.ts 1.29 KiB [built] [code generated]
external "~/package.json" 42 bytes [optional] [built] [code generated]

WARNING in ./app/components/Audio.svelte
Module Warning (from ./node_modules/svelte-loader/index.js):
Unused CSS selector ".audio" (11:0)
 9: </script>
10: <style>
11: .audio {
    ^
12:     color: #ca9ed9;
13: }
 @ ./app/components/Home.svelte 26:0-24
 @ ./app/App.svelte 21:0-44 32:12-16 85:34-38
 @ ./app/app.ts 9:0-31 10:20-23

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.74.0 compiled with 1 warning in 2732 ms
Webpack compilation complete.
Cannot find module '@nativescript/webpack/lib/before-checkForChanges.js'
Require stack:
- /home/ettinger/www/calmness.io/calmness-mobile/hooks/before-checkForChanges/nativescript-webpack.js
- /home/ettinger/.nvm/versions/node/v18.7.0/lib/node_modules/nativescript/lib/common/services/hooks-service.js
- /home/ettinger/.nvm/versions/node/v18.7.0/lib/node_modules/nativescript/lib/common/yok.js
- /home/ettinger/.nvm/versions/node/v18.7.0/lib/node_modules/nativescript/lib/bootstrap.js
- /home/ettinger/.nvm/versions/node/v18.7.0/lib/node_modules/nativescript/lib/nativescript-cli.js
- /home/ettinger/.nvm/versions/node/v18.7.0/lib/node_modules/nativescript/bin/tns

module.exports = require("@nativescript/core/cli-hooks/before-checkForChanges.js");

chovy
  • 72,281
  • 52
  • 227
  • 295
  • 1
    Check out this solution: https://github.com/NativeScript/nativescript-cli/issues/5546 as your problem is basically Cannot find module '@nativescript/webpack/lib/before-checkForChanges.js' – MatiK Sep 02 '22 at 22:21

2 Answers2

1

Sometimes NativeScript leaves some broken (or outdated) files inside platforms or hooks (from old builds before upgrading something or even aborted builds).

For that, I usually add the npm script clean:

rm -rf node_modules platforms hooks

The ns app template and cli command include deleting package-lock.json, I'm not comfortable with losing the specific versions locked.

Clearing also node_modules makes plugins to re-run postinstall scripts, some plugins will not recreate their hooks otherwise.

Then just install deps and build the project again npm install && ns build android. Good luck.

That assuming your dependencies are right and have matching versions between them.

(Following the link from @Matik in the comments)

Xiromoreira
  • 103
  • 1
  • 7
  • You should just run 'ns clean' ...it does the same thing and cleans up some other things as well. – Nick Wiltshire Dec 26 '22 at 04:19
  • @NickWiltshire as I stated, it also deletes `package-lock.json` and I don't feel that is a good approach. It has given me issues while trying to update legacy projects and dependencies not well specified (or maintainers not respecting semver). It defies the purpose of the lock file. – Xiromoreira Dec 27 '22 at 12:06
-1

try running

npm install

then run ns or tns build android

Nehal Sk
  • 41
  • 3