padlocal / wechaty-puppet-padlocal-demo

65 stars 35 forks source link

Support ESM module please #16

Open suntong opened 2 years ago

suntong commented 2 years ago

Versions

What is your wechaty version?

Answer: wechaty@1.20.2

Which puppet are you using for wechaty? (puppeteer/padlocal/service...)

Answer: padlocal

What is your wechaty-puppet-XXX(padchat/puppeteer/) version?

Answer: wechaty-puppet-padlocal@1.20.1

What is your node version? (run node --version)

Answer: v16.14.0

To Reproduce

Steps to reproduce the behavior:

  1. Follow the Quick Start guide from https://github.com/padlocal/wechaty-puppet-padlocal-demo/
  2. Download main.mjs and helper.mjs from here, and put them where main.ts is
  3. run node main.mjs after export WECHATY_PUPPET=wechaty-puppet-padlocal WECHATY_PUPPET_PADLOCAL_TOKEN=puppet_padlocal_xxx

The bug

will get ReferenceError: require is not defined:

$ node main.mjs 
19:21:45 INFO 
      ============================================================
       Welcome to Wechaty PadLocal puppet!

       - puppet-padlocal version: 1.20.1
       - padlocal-ts-client version: 0.5.3
      ============================================================

19:21:45 INFO [PadLocalDemo] started.
19:21:47 INFO [PuppetPadlocal] start login with type: QrLogin
19:21:50 INFO [PadLocalDemo] onScan: Waiting(2) - https://wechaty.js.org/qrcode/http%3A%2F%2Fweixin.qq.com%2Fx%2FAbaw84QP3rB6uX6zHLAW
ReferenceError: require is not defined
    at WechatyImpl.<anonymous> (file:///nodejs/step1/wechaty-puppet-padlocal-demo/main.mjs:22:7)
    at WechatyImpl.emit (node:events:520:28)
    at WechatyImpl.emit (file:///nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/wechaty/dist/esm/src/wechaty-mixins/gerror-mixin.js:31:30)
    at PuppetPadlocal.<anonymous> (file:///nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/wechaty/dist/esm/src/wechaty-mixins/puppet-mixin.js:343:34)
    at PuppetPadlocal.emit (node:events:532:35)
    at PuppetPadlocal.emit (file:///nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet/dist/esm/src/puppet/puppet-skeleton.js:84:26)
    at Object.onQrCodeEvent (file:///nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet-padlocal/dist/esm/src/puppet-padlocal.js:113:18)
    at Request.request.onMessageCallback (/nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/padlocal-client-ts/dist/PadLocalClientApi.js:63:34)
    at Request.<anonymous> (/nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/padlocal-client-ts/dist/Request.js:175:91)
    at Generator.next (<anonymous>)

$ grep require /nodejs/step1/wechaty-puppet-padlocal-demo/node_modules/padlocal-client-ts/dist/Request.js
const padlocal_pb_1 = require("./proto/padlocal_pb");
const ActionMessageUtils_1 = require("./utils/ActionMessageUtils");
const PromiseUtils_1 = require("./utils/PromiseUtils");
const WeChatShortLinkProxy_1 = require("./link/WeChatShortLinkProxy");
const verror_1 = __importDefault(require("verror"));
const Utils_1 = require("./utils/Utils");
const SocketStreamHandler_1 = require("./link/SocketStreamHandler");
const LongLinkStreamHandler_1 = require("./link/LongLinkStreamHandler");
const PushStreamHandler_1 = require("./link/PushStreamHandler");
const GrpcClient_1 = require("./GrpcClient");
const PadLocalClientPlugin_1 = require("./PadLocalClientPlugin");
const FileUploadStreamHandler_1 = require("./link/FileUploadStreamHandler");
const ByteUtils_1 = require("./utils/ByteUtils");
const WeChatHttpProxy_1 = require("./link/WeChatHttpProxy");
const Log_1 = __importDefault(require("./utils/Log"));

Basically

Somehow packaging from padlocal-client-ts for ESM is not done right.

Please double check.

suntong commented 2 years ago

the two code is almost the same. One works and one doesn't. Here is the key changes:

image

and now it is working. So I'd conclude that the ESM module support is broken.