nativescript 找不到模块 'platform'
nativescript Cannot find module 'platform'
在 Nativescript after-prepare hook 中,我想找出 nativescript 正在准备的当前平台,以便我可以做不同的事情。所以我添加了
require("platform");
但是当我tns prepare android
时,我总是得到以下错误:
Error: Cannot find module 'platform'
当我尝试在 require("platform");
上方添加 require("http");
时,require("http");
没有给我错误。这两种情况有什么区别?为什么 require("platform");
失败但 require("http");
成功?
http 模块和平台模块都在 tns-core-modules 文件夹中。
您不能在挂钩内使用 TNS 核心模块。根据您尝试做的事情,使用 gulp 或类似的东西可能会更好。然后在您的 package.json 中创建脚本以执行任一平台所需的流程,然后 运行 nativescript 流程。
例如。
package.json
scripts": {
"android-stuff": "gulp yourTask && tns run android",
在 Nativescript after-prepare hook 中,我想找出 nativescript 正在准备的当前平台,以便我可以做不同的事情。所以我添加了
require("platform");
但是当我tns prepare android
时,我总是得到以下错误:
Error: Cannot find module 'platform'
当我尝试在 require("platform");
上方添加 require("http");
时,require("http");
没有给我错误。这两种情况有什么区别?为什么 require("platform");
失败但 require("http");
成功?
http 模块和平台模块都在 tns-core-modules 文件夹中。
您不能在挂钩内使用 TNS 核心模块。根据您尝试做的事情,使用 gulp 或类似的东西可能会更好。然后在您的 package.json 中创建脚本以执行任一平台所需的流程,然后 运行 nativescript 流程。
例如。
package.json
scripts": {
"android-stuff": "gulp yourTask && tns run android",