arcanis/clipanion

ESM exports are broken

otakustay opened this issue · 6 comments

Version 3.2.0-rc.15 has an exports field in package.json which point ESM imports to ./lib/advanced/index.mjs, however ./lib/advanced/Cli.mjs has a broken directory import:

import { getCaptureActivator, getDefaultColorDepth } from '../platform';

In Node's ESM module, imports must reference to a specific file, either ./platform/node.mjs or ./platform/browser.mjs, current code results errors like:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/root/codes/baidu_finance-cloud_aimp-customer-analysis-fe/baidu/finance-cloud/aimp-customer-analysis-fe/node_modules/clipanion/lib/platform' is not supported resolving ES modules imported from /root/codes/baidu_finance-cloud_aimp-customer-analysis-fe/baidu/finance-cloud/aimp-customer-analysis-fe/node_modules/clipanion/lib/advanced/Cli.mjs
    at new NodeError (node:internal/errors:377:5)
    at finalizeResolution (node:internal/modules/esm/resolve:401:17)
    at moduleResolve (node:internal/modules/esm/resolve:966:10)
    at defaultResolve (node:internal/modules/esm/resolve:1174:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file://.../node_modules/clipanion/lib/platform'
}

Same errors here, with different error message from yarn.

Error: Qualified path resolution failed: we looked for the following paths, but none could be accessed.

Source path: /***/.yarn/__virtual__/clipanion-virtual-55a2e96ea7/0/cache/clipanion-npm-3.2.0-rc.15-1a049119c3-b8b730aacb.zip/node_modules/clipanion/lib/platform
Not found: /***/.yarn/__virtual__/clipanion-virtual-55a2e96ea7/0/cache/clipanion-npm-3.2.0-rc.15-1a049119c3-b8b730aacb.zip/node_modules/clipanion/lib/platform
Not found: /***/.yarn/__virtual__/clipanion-virtual-55a2e96ea7/0/cache/clipanion-npm-3.2.0-rc.15-1a049119c3-b8b730aacb.zip/node_modules/clipanion/lib/platform/node

Same

It seems they use a inner folder package "lib/platform", but without testing its behavior under esm.
Downgrading to rc.14 solve my problem.

Currently in a train, I'll revert the change as soon as I get a stable network. Sorry for the inconvenience 🙁

Revert shipped with the 3.2.0-rc.16

esm is still broken, this yarn patch works for me:

diff --git a/lib/platform/package.json b/lib/platform/package.json
index 5ea9d43740d1bdb509612376c0e9ce91d20f8b20..2802dcd72971987c4567957e73d73b1bef1edc9e 100644
--- a/lib/platform/package.json
+++ b/lib/platform/package.json
@@ -1,4 +1,4 @@
 {
-    "main": "./node",
-    "browser": "./browser"
+    "main": "./node.js",
+    "browser": "./browser.js"
 }
diff --git a/package.json b/package.json
index cbf943bcc31a864f2771e457d327e5106eba9afe..74c10ad057ebe7ce5289ae25e9cca4f17479a639 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
     "command"
   ],
   "version": "3.2.1",
-  "main": "lib/advanced/index",
+  "main": "lib/advanced/index.js",
   "license": "MIT",
   "sideEffects": false,
   "repository": {
@@ -65,7 +65,7 @@
     "demo": "node --require ts-node/register demos/advanced.ts"
   },
   "publishConfig": {
-    "main": "lib/advanced/index"
+    "main": "lib/advanced/index.js"
   },
   "files": [
     "lib"