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

How to add module to disallowedModules? #1036

Closed
gajus opened this issue Jan 26, 2023 · 10 comments · May be fixed by #1037
Closed

How to add module to disallowedModules? #1036

gajus opened this issue Jan 26, 2023 · 10 comments · May be fixed by #1037
Labels
enhancement New feature or request

Comments

@gajus
Copy link

gajus commented Jan 26, 2023

We need to exclude a module from being bundled.

Contrary to the documentation, ignoreModules does not achieve that.

@gajus gajus added the enhancement New feature or request label Jan 26, 2023
@bergundy
Copy link
Member

Can you please provide more information why ignoreModules doesn't achieve what you want?
Here's what the bundler does internally FTR:

.
Here's a test that successfully ignores dns
test('Workflow bundle can be created from code using ignoreModules', async (t) => {
.

@gajus
Copy link
Author

gajus commented Jan 26, 2023

I've added ['slonik', 'node:crypto'] and still getting error:

2023-01-26T16:23:52.171Z [ERROR] ERROR in node:crypto
2023-01-26T16:23:52.171Z [ERROR] Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
2023-01-26T16:23:52.171Z [ERROR] Webpack supports "data:" and "file:" URIs by default.
2023-01-26T16:23:52.171Z [ERROR] You may need an additional plugin to handle "node:" URIs.

so it seems at least one of them is still being included

@gajus
Copy link
Author

gajus commented Jan 26, 2023

Actually, now that I look at the Temporal source code, there is no logic there to actually exclude module. It only adds a warning if it is not already excluded.

@gajus
Copy link
Author

gajus commented Jan 26, 2023

It seems that it attempts to exclude it using alias, which unfortunately does not work for modules such as node:

webpack/webpack#14166

@bergundy
Copy link
Member

LMK if removing the node: prefix solves your issue for now.

@gajus
Copy link
Author

gajus commented Jan 26, 2023

LMK if removing the node: prefix solves your issue for now.

It does not, as explained in that webpack issue.

@gajus
Copy link
Author

gajus commented Jan 26, 2023

I have no control over node: referenced in code, as it is coming from dependencies.

@mjameswh
Copy link
Contributor

mjameswh commented Jan 26, 2023

The issue you are facing is not directly about ignoreModules. It is that the workflow bundler is not compiling for the node target, and therefore, webpack does not even know how to process dependencies in the node: namespace.

Would it be possible for you to ignore the module that does import that node: dependency?

@gajus
Copy link
Author

gajus commented Jan 26, 2023

That's what I am trying to do with externals.

Anyway, overriding externals does the job.

// @see https://github.com/temporalio/sdk-typescript/issues/1036#issuecomment-1405322953
config.externals = {
  "node:crypto": "{}"
};

@gajus
Copy link
Author

gajus commented Jan 26, 2023

A Temporal-compatible patch:

const temporalExternals = config.externals;

config.externals = async (context, callback) => {
  if (context.request === 'node:crypto') {
    return 'var {}';
  }

  return temporalExternals(context, callback);
};

config.resolve.alias = {
  ...config.resolve.alias,
  '@': path.resolve(__dirname, '../..'),
  slonik: false,
};

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

Successfully merging a pull request may close this issue.

3 participants