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

Radpack fails when requiring/importing node built-in module #22

Closed
jared-smith-kr opened this issue Oct 15, 2021 · 2 comments
Closed

Radpack fails when requiring/importing node built-in module #22

jared-smith-kr opened this issue Oct 15, 2021 · 2 comments

Comments

@jared-smith-kr
Copy link

We're experimenting with using radpack with rollup for module federation in in a node.js application and we're having problems when requiring/importing node.js built-in modules, in particular worker_threads:

import { isMainThread, parentPort, Worker } from 'worker_threads'
// error! unknown export 'worker_threads'

The traceback points at this line of code in radpack rollup plugin which as far as I can read is choking because it can't find the index for that package in the registry map.

Did we do something wrong or is there a way to tell the process to defer resolution of that package to runtime or something else that would solve this?

@trhinehart-godaddy
Copy link
Collaborator

This is somewhat by design, as by default radpack libraries built with the rollup plugin are meant to be universal (work on the client and sever). As a workaround, try using @rollup/plugin-node-resolve with preferBuiltins as true and use rollup-plugin-external-globals with a configuration to use the available global.require that will bypass rollup's default behavior.

{
  plugins: [
    nodeResolve({ preferBuiltins: true }),
    externalGlobals({
      'worker_threads': `(global.require(${ JSON.stringify('worker_threads') }))`
    })
  ]
}

@jared-smith-kr
Copy link
Author

That seems to be working. Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants