Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESM module please #16

Open
suntong opened this issue Jun 11, 2022 · 1 comment
Open

Support ESM module please #16

suntong opened this issue Jun 11, 2022 · 1 comment

Comments

@suntong
Copy link

suntong commented Jun 11, 2022

Versions

What is your wechaty version?

Answer: [email protected]

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

Answer: padlocal

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

Answer: [email protected]

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

  • CommonJS uses the require('./xx') syntax, while
  • ESM uses the import {stuff} from './xx' syntax

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

Please double check.

@suntong
Copy link
Author

suntong commented Jun 26, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant