appium-boneyard / appium-plugins

Officially-maintained plugins for the Appium server
Apache License 2.0
32 stars 7 forks source link

Trying to Create Local Plugin #101

Closed VinayBerry closed 2 years ago

VinayBerry commented 2 years ago

I'm trying to create a local plugin but its complaining about the use of import statement outside of a module. If I convert the package to type: module, then this appears "Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\milks\node\appium-plugin\index.js". Not sure what I'm missing to make this work.

I tried cloning this repository and installing the 'images' plugin and gives the same error.

PS C:\Users\vberry\node> appium --use-plugins=images
[Appium] Attempting to load plugin images...
[Appium] Could not load plugin 'images', so it will not be available. Error in loading the plugin was: Cannot use import statement outside a module
[debug] [Appium] C:\Users\milks\node\appium-plugins\packages\images\index.js:1
[debug] [Appium] import ImageElementPlugin, { IMAGE_STRATEGY } from './lib/plugin';
[debug] [Appium] ^^^^^^
[debug] [Appium] SyntaxError: Cannot use import statement outside a module
[debug] [Appium]     at Object.compileFunction (node:vm:352:18)
[debug] [Appium]     at Module._compile (node:internal/modules/cjs/loader:1063:27)
[debug] [Appium]     at Module.load (node:internal/modules/cjs/loader:975:32)
[debug] [Appium]     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
[debug] [Appium]     at Module.require (node:internal/modules/cjs/loader:999:19)
[debug] [Appium]     at PluginConfig.require (C:\Program Files\nodejs\node_modules\npm\node_modules\appium\lib\extension-config.js:283:12)
[debug] [Appium]     at map (C:\Program Files\nodejs\node_modules\npm\node_modules\appium\lib\main.js:122:76)
[debug] [Appium]     at Array.map (<anonymous>)
[debug] [Appium]     at getActivePlugins (C:\Program Files\nodejs\node_modules\npm\node_modules\appium\lib\main.js:119:5)
[debug] [Appium]     at main (C:\Program Files\nodejs\node_modules\npm\node_modules\appium\lib\main.js:303:25)

If I install directly from npm instead of from the cloned repository and use the images plugin everything works fine.

VinayBerry commented 2 years ago

https://github.com/VinayBerry/custom-appium-plugin <- link to my repository

VinayBerry commented 2 years ago

nevermind i figured out you guys are using tsc in the example and pointing to the build folder. I also did this and mine worked.

jlipps commented 2 years ago

👍

jlipps commented 2 years ago

let us know when your plugin is done!