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

require('node:module')._preloadModules is not a function. #6227

Closed
imcm7 opened this issue Oct 2, 2023 · 9 comments · Fixed by #14227
Closed

require('node:module')._preloadModules is not a function. #6227

imcm7 opened this issue Oct 2, 2023 · 9 comments · Fixed by #14227
Labels
bug Something isn't working good first issue Something that would be good for new contributors node.js Compatibility with Node.js APIs

Comments

@imcm7
Copy link

imcm7 commented Oct 2, 2023

What version of Bun is running?

1.0.2+37edd5a6e389265738e89265bcbdf2999cb81a49

What platform is your computer?

Linux 6.2.0-33-generic x86_64 x86_64

What steps can reproduce the bug?

https://github.com/imcm7/nuxt-db/tree/main/server
install mikro-orm and bun -b db:update

What is the expected behavior?

No response

What do you see instead?

@Jarred-Sumner with -b also not run, some days ago all was ok

process[exports.REGISTER_INSTANCE] = service;
132 |     // Register the extensions.
133 |     registerExtensions(service.options.preferTsExts, service.extensions.compiled, service, originalJsHandler);
134 |     (0, cjs_resolve_hooks_1.installCommonjsResolveHooksIfNecessary)(service);
135 |     // Require specified modules before start-up.
136 |     module_1.Module._preloadModules(service.options.require);
        ^
TypeError: module_1.Module._preloadModules is not a function. (In 'module_1.Module._preloadModules(service.options.require)', 'module_1.Module._preloadModules' is undefined)
      at register (/home/node/nuxt/node_modules/ts-node/dist/index.js:136:4)
      at /home/node/nuxt/node_modules/@mikro-orm/core/utils/ConfigurationLoader.js:115:28
      at registerTsNode (/home/node/nuxt/node_modules/@mikro-orm/core/utils/ConfigurationLoader.js:104:32)
      at /home/node/nuxt/node_modules/@mikro-orm/cli/CLIConfigurator.js:28:33
      at processTicksAndRejections (:55:76)
error: script "db:update" exited with code 1 (SIGHUP)

``

### Additional information

_No response_
@imcm7 imcm7 added the bug Something isn't working label Oct 2, 2023
@B4nan
Copy link

B4nan commented Oct 2, 2023

I think you should drop the useTsNode option from your package.json, that option triggers the ts-node.register() which you don't need with bun. Instead, you need the new alwaysAllowTs option, which will make the ORM respect the TS files, but as opposed to the useTsNode it won't trigger the ts-node.register() call.

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Oct 2, 2023
@Electroid Electroid changed the title module_1.Module._preloadModules is not a function. (In 'module_1.Module._preloadModules(service.options.require)', 'module_1.Module._preloadModules' is undefined) module_1.Module._preloadModules is not a function. Oct 2, 2023
@Electroid Electroid changed the title module_1.Module._preloadModules is not a function. _preloadModules is not a function. Oct 2, 2023
@imcm7
Copy link
Author

imcm7 commented Oct 3, 2023

@B4nan with pnpm also not work

@notramo
Copy link

notramo commented Nov 24, 2023

Is this issue still relevant?
commitlint works in Bun 1.0.14, which was previously crashing because of this bug.

@Jarred-Sumner
Copy link
Collaborator

@paperdave fixed this some time ago

@notramo
Copy link

notramo commented Nov 24, 2023

@Jarred-Sumner I checked it again, and commitlint crashes if the node_modules were installed by pnpm (but works if it was installed by Bun). Since the Bun built-in package manager is highly unusable for complex scenarios (e.g. workspaces), it's very likely that some projects use pnpm for package management, and Bun for everything else.

@paperdave
Copy link
Member

this issue is not fixed as of 1.0.14. the work seems to be started on pr here: #6188. i did not have time to finish it up at the time, and i am now focusing on the windows build. someone else will have to pickup implementing the node:module internal apis.

@paperdave paperdave reopened this Nov 24, 2023
@paperdave paperdave changed the title _preloadModules is not a function. require('node:module')._preloadModules is not a function. Nov 24, 2023
@PaulRBerg
Copy link

Getting this error in a GitPod instance of my Hardhat template:

An unexpected error occurred:

131 |     process[exports.REGISTER_INSTANCE] = service;
132 |     // Register the extensions.
133 |     registerExtensions(service.options.preferTsExts, service.extensions.compiled, service, originalJsHandler);
134 |     (0, cjs_resolve_hooks_1.installCommonjsResolveHooksIfNecessary)(service);
135 |     // Require specified modules before start-up.
136 |     module_1.Module._preloadModules(service.options.require);
          ^
TypeError: module_1.Module._preloadModules is not a function. (In 'module_1.Module._preloadModules(service.options.require)', 'module_1.Module._preloadModules' is undefined)
      at register (/workspace/hardhat-template/node_modules/ts-node/dist/index.js:136:5)
      at /workspace/hardhat-template/node_modules/ts-node/register/transpile-only.js:1:1
      at loadTsNode (/workspace/hardhat-template/node_modules/hardhat/internal/core/typescript-support.js:71:5)
      at /workspace/hardhat-template/node_modules/hardhat/internal/cli/cli.js:127:17
      at main (/workspace/hardhat-template/node_modules/hardhat/internal/cli/cli.js:75:23)
      at /workspace/hardhat-template/node_modules/hardhat/internal/cli/cli.js:305:1
      at /workspace/hardhat-template/node_modules/hardhat/internal/cli/bootstrap.js:15:1

@ashayp22
Copy link

ashayp22 commented Jul 3, 2024

Getting this error with macOS arm64, Bun v1.1.17 and threads.js v1.7.0 when setting up a pool with thread.js.

Error

Screenshot 2024-07-03 at 1 59 11 PM

Setup

// index.ts
import { spawn, Pool, Worker } from "threads";

const pool = Pool(
  () => spawn(new Worker("./workers/add")),
  8
);
// workers/add.ts
import { expose } from "threads/worker"

expose(function add(a, b) {
  return a + b
})

@Jarred-Sumner
Copy link
Collaborator

Confirming this is not fixed, and also probably very easy to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Something that would be good for new contributors node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants