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

Can't run development mode with bun #934

Closed
pe1uca opened this issue Feb 1, 2024 · 2 comments · Fixed by #966
Closed

Can't run development mode with bun #934

pe1uca opened this issue Feb 1, 2024 · 2 comments · Fixed by #966
Labels
bug Something isn't working

Comments

@pe1uca
Copy link

pe1uca commented Feb 1, 2024

Describe the bug

  1. ts-node throws config:ts-node TypeError: module_1.Module._preloadModules is not a function.
  2. With a workaround for the issue above oclif throws this warning warn: Requested module is not instantiated yet

To Reproduce
Steps to reproduce the behavior:

  1. Create a new oclif project bunx oclif generate pe1ucaCLI
  2. In bin/dev replace the first line with #!/usr/bin/env bun
  3. In the same file comment require('ts-node').register({project})
  4. Run bin/dev hello:world
  5. See oclif doesn't find the example command

Expected behavior
oclif should run the commands from the source code.

Screenshots

Environment (please complete the following information):

  • OS & version: Ubuntu 22.04.3 LTS
  • Shell/terminal & version bash-5.1.16

Additional context

require('ts-node').register({project}) throws an error due to an issue with bun oven-sh/bun#6227
Since bun has typescript as first-class citizen this dependency is not necessary.
But commenting this line is not enough, since oclif/core has another call to register

tsNode.register(conf)

Commenting both of these lines makes oclif properly load the source code.
Before commenting the line in core

config loading core plugin from /home/pe1uca/Documents/pe1ucaCLI +0ms
config:ts-node registering ts-node at /home/pe1uca/Documents/pe1ucaCLI +0ms
config:ts-node ts-node path: /home/pe1uca/Documents/pe1ucaCLI/node_modules/ts-node/dist/index.js +0ms
config:ts-node TypeError: module_1.Module._preloadModules is not a function. (In 'module_1.Module._preloadModules(service.options.require)', 'module_1.Module._preloadModules' is undefined)
config:ts-node     at register (/home/pe1uca/Documents/pe1ucaCLI/node_modules/ts-node/src/index.ts:4:37)
config:ts-node     at /home/pe1uca/Documents/pe1ucaCLI/node_modules/@oclif/core/lib/config/ts-node.js:58:13
config:ts-node     at processTicksAndRejections (:13:78) +28ms
config:pe1ucaCLI loading IDs from /home/pe1uca/Documents/pe1ucaCLI/dist/commands +0ms
config:pe1ucaCLI found commands [] +11ms

After commenting it

config:ts-node registering ts-node at /home/pe1uca/Documents/pe1ucaCLI +0ms
config:ts-node ts-node path: /home/pe1uca/Documents/pe1ucaCLI/node_modules/ts-node/dist/index.js +0ms
config:ts-node tsconfig: {
config:ts-node   <tsconfig>
config:ts-node } +14ms
config:ts-node ts-node options: {
config:ts-node   <ts-node options>
config:ts-node } +1ms
config:ts-node determining path for /home/pe1uca/Documents/pe1ucaCLI/dist/commands +0ms
config:ts-node lib dir: /home/pe1uca/Documents/pe1ucaCLI/dist +0ms
config:ts-node src dir: /home/pe1uca/Documents/pe1ucaCLI/src +0ms
config:ts-node src commands dir: /home/pe1uca/Documents/pe1ucaCLI/src/commands +0ms
config:ts-node Found source file for /home/pe1uca/Documents/pe1ucaCLI/dist/commands at /home/pe1uca/Documents/pe1ucaCLI/src/commands +0ms
config:pe1ucaCLI loading IDs from /home/pe1uca/Documents/pe1ucaCLI/src/commands +0ms
config:pe1ucaCLI found commands [
<list of all commands in src>
] +12ms

With the fix above the warning warn: Requested module is not instantiated yet shows up, can't see something in my project affected by this, the commands run properly.
Seems related to this part of the code

const isPlugin = (config: IConfig | IPlugin): config is IPlugin => (<IPlugin>config).type !== undefined

Here's the log

warn: Requested module is not instantiated yet.
    at link (:1:11)
    at linkAndEvaluateModule (:1:11)
    at <anonymous> (/home/pe1uca/Documents/pe1ucaCLI/node_modules/@oclif/core/lib/module-loader.js:16:93)
    at processTicksAndRejections (:12:39)
module: @oclif/core@3.18.2
task: cacheCommand
plugin: pe1ucaCLI
root: /home/pe1uca/Documents/pe1ucaCLI
See more details with DEBUG=*
warn: Requested module is not instantiated yet.
    at link (:1:11)
    at linkAndEvaluateModule (:1:11)
    at <anonymous> (/home/pe1uca/Documents/pe1ucaCLI/node_modules/@oclif/core/lib/module-loader.js:16:93)
    at processTicksAndRejections (:12:39)
module: @oclif/core@3.18.2
task: cacheCommand
plugin: pe1ucaCLI
root: /home/pe1uca/Documents/pe1ucaCLI
See more details with DEBUG=*
@pe1uca
Copy link
Author

pe1uca commented Feb 1, 2024

Seems the issue with the requested module cause by trying to load a command with an import with a relative path.
import * as config from '../../config';

Removing this import makes the warning disappear.

@mdonnalley mdonnalley added the bug Something isn't working label Feb 21, 2024
Copy link

git2gus bot commented Feb 21, 2024

This issue has been linked to a new work item: W-15093833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants