wechaty / puppet-padlocal

Puppet PadLocal is a Pad Protocol for WeChat
https://wechaty.js.org/docs/puppet-providers/padlocal
Apache License 2.0
642 stars 88 forks source link

Failed to run demo #141

Closed padlocal closed 2 years ago

padlocal commented 2 years ago

@huan I am working on branch esm with lastest code. Found that it was failed to start the embeded demo by running npm run demo.

Error stack

$ npm run demo

> wechaty-puppet-padlocal@1.11.7 demo
> cross-env ts-node examples/demo.ts

Error: Cannot find module '../src/puppet-padlocal.js'
Require stack:
- /Users/haoda/github/wechaty-puppet-padlocal/examples/demo.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/haoda/github/wechaty-puppet-padlocal/node_modules/@chatie/tsconfig/node_modules/ts-node/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/haoda/github/wechaty-puppet-padlocal/examples/demo.ts:9:55)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module.m._compile (/Users/haoda/github/wechaty-puppet-padlocal/node_modules/@chatie/tsconfig/node_modules/ts-node/src/index.ts:1459:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/haoda/github/wechaty-puppet-padlocal/node_modules/@chatie/tsconfig/node_modules/ts-node/src/index.ts:1462:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/haoda/github/wechaty-puppet-padlocal/examples/demo.ts' ]
}

I think it's related to esm-supporting feature code, then how can I make it work temporary? I am working on bugs fixing that we talked on meetup.

Thanks!

huan commented 2 years ago

I have removed all the .js in the import code by using the below regexp:

(\s+from\s+".+)\.js";

to

$1";

Related commit:

After that the npm run demo works.

I think we can upgrade the padlocal to the Wechaty v1.x API for now, and leave all the ESM works after the v1.x upgrade.