You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I can't use an ESM package in a CJS plugin if I link it into a CJS CLI.
Node supports loading an ESM package in commonjs code via await import and this works when running commands with bin/run and bin/dev if you set moduleResolution to node16 in the tsconfig but not when linking the plugin. This only affects linked plugins, it will work if you publish and install the plugin.
➜ hello-world git:(main) sf hello world
Error: require() of ES Module /Users/cdominguez/code/gh/hello-world/node_modules/chalk/source/index.js from
/Users/cdominguez/code/gh/hello-world/src/commands/hello/world.ts not supported.
Instead change the require of index.js in /Users/cdominguez/code/gh/hello-world/src/commands/hello/world.ts to a dynamic import() which is available in all CommonJS
modules.
Code: ERR_REQUIRE_ESM
Expected behavior
linked command should work fine.
Findings
I compiled the command with ts-node to verify that it was respecting my tsconfig and not replacing the await import, looks correct here:
I tested this by modifying the oclif/core/lib/config/ts-node.js file to conditionally set it and worked but I'm not sure how it could affect CJS<->ESM interop.
In the lower right corner you can see there's 2 linked plugins, but only hello-world has moduleResolution set to node16. The conditional approach doesn't seem to break plugins without this prop set.
The text was updated successfully, but these errors were encountered:
Describe the bug
I can't use an ESM package in a CJS plugin if I link it into a CJS CLI.
Node supports loading an ESM package in commonjs code via
await import
and this works when running commands with bin/run and bin/dev if you setmoduleResolution
tonode16
in the tsconfig but not when linking the plugin.This only affects linked plugins, it will work if you publish and install the plugin.
To Reproduce
yarn install && yarn build
./bin/run hello world
works, same withbin/dev
sf plugins link .
sf hello world
, you get:Expected behavior
linked command should work fine.
Findings
I compiled the command with ts-node to verify that it was respecting my tsconfig and not replacing the
await import
, looks correct here:then looked at the ts-node code in oclif/core and found that it doesn't pass the
moduleResolution
prop here:https://github.com/oclif/core/blob/main/src/config/ts-node.ts#L59-L72
I tested this by modifying the
oclif/core/lib/config/ts-node.js
file to conditionally set it and worked but I'm not sure how it could affect CJS<->ESM interop.In the lower right corner you can see there's 2 linked plugins, but only
hello-world
hasmoduleResolution
set tonode16
. The conditional approach doesn't seem to break plugins without this prop set.The text was updated successfully, but these errors were encountered: