0

In Nativescript after-prepare hook, I want to find out the current platform that the nativescript is preparing for so that I can do different things. So I added

require("platform");

But when I do tns prepare android, I always get the following error:

Error: Cannot find module 'platform'

When I tried adding require("http"); above the require("platform");, require("http");does not give me error. What is the difference between these two cases? Why require("platform"); fails but require("http"); succeed?

Both http module and platform module are in tns-core-modules folder.

asked Jan 27, 2018 at 11:39
0

1 Answer 1

1

You cannot use the TNS core modules inside the hooks. Depending on what your trying to do maybe it would be better to use gulp or something like it. Then create scripts in your package.json to do the processes you need for either platform and then run the nativescript process.

for example.

package.json

scripts": {
 "android-stuff": "gulp yourTask && tns run android",
answered Jan 28, 2018 at 15:49
Sign up to request clarification or add additional context in comments.

2 Comments

Could you elaborate more on why TNS core modules can not be used inside the hooks?
The tns core modules are abstractions for Android and iOS. The hooks have more to do with the build processes and file systems. Check out github.com/NativeScript/nativescript-dev-sass it uses the hooks to build sass. hope that helps

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.