tinylibs / tinyexec

📟 A tiny, higher level interface around child_process
MIT License
116 stars 2 forks source link

Dynamic require of "child_process" is not supported when importing from esm #17

Closed yyx990803 closed 2 months ago

yyx990803 commented 3 months ago

In a project with type: "module" and:

import { x } from 'tinyexec'

throws:

file:///XXX/node_modules/.pnpm/tinyexec@0.1.2/node_modules/tinyexec/dist/main.js:11
  throw Error('Dynamic require of "' + e + '" is not supported');
        ^

Error: Dynamic require of "child_process" is not supported
    at file:///XXX/node_modules/.pnpm/tinyexec@0.1.2/node_modules/tinyexec/dist/main.js:11:9
    at file:///XXX/node_modules/.pnpm/tinyexec@0.1.2/node_modules/tinyexec/dist/main.js:347:12
    at file:///XXX/node_modules/.pnpm/tinyexec@0.1.2/node_modules/tinyexec/dist/main.js:13:31
    at file:///XXX/node_modules/.pnpm/tinyexec@0.1.2/node_modules/tinyexec/dist/main.js:411:13
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
43081j commented 3 months ago

That's very strange. The cjs entry point checks for require and throws that if it is undefined (bundler code by the looks of it, not ours)

Is the resolution going wonky for you maybe and it should have resolved to the esm entry point?

43081j commented 2 months ago

@yyx990803 i figured this out somewhat

it seems to be weird tsup behaviour. im tracking it in #20

43081j commented 2 months ago

should be fixed by #21