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

[Service Bus] Long term fix for duplication of module references by rush + node-resolve rollup plugin #3326

Closed
2 tasks done
ramya0820 opened this issue May 31, 2019 · 15 comments · Fixed by #4613
Closed
2 tasks done
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system. Service Bus

Comments

@ramya0820
Copy link
Member

ramya0820 commented May 31, 2019

The fix deployed for #3119 involves removing duplicate references to Buffer module after they have been generated.
This issue is to investigate why the duplication is happening, and deploy a long term fix for same issue that would not require us to post-process and remove the duplicates.

  • Investigate what is causing duplication of the Buffer module on disabling the dedupe flag on node-resolve plugin
  • Identify suitable fix and deploy
@ramya0820 ramya0820 added Client This issue points to a problem in the data-plane of the library. Service Bus labels May 31, 2019
@ramya0820 ramya0820 added the EngSys This issue is impacting the engineering system. label May 31, 2019
@mikeharder mikeharder self-assigned this Jun 1, 2019
@ramya0820 ramya0820 removed their assignment Jun 4, 2019
@ramya0820
Copy link
Member Author

Following are some notes that could help with further investigation from Eng Sys side -

Qs to answer:

  • Why is duplication happening?
  • Why is duplication bad?
  • How does de-dupe in rollup work?
  • How is the build step making a difference to rollup output?

Things that can be tried:

  • If allowing dupe vs de-dupe creates any different outputs with using just npm
  • Check role of amqp-common by not having rush refer to local instance and pull it from registry instead.

@KarishmaGhiya
Copy link
Contributor

KarishmaGhiya commented Jun 6, 2019

https://www.npmjs.com/package/rollup-plugin-node-resolve/v/4.2.0 See the Usage section for:

// Force resolving for these modules to root's node_modules that helps
      // to prevent bundling the same package multiple times if package is
      // imported from dependencies.
      dedupe: [ 'react', 'react-dom' ], // Default: []

Changelog for this:
https://diff.intrinsic.com/rollup-plugin-node-resolve/4.1.0/4.2.0

https://github.com/rollup/rollup-plugin-node-resolve/releases/tag/v4.2.0

Going through the above links, this seems like the duplication of module references was expected by their code change when they moved from version 4.1.0 to 4.2.0 for rollup-plugin-node-resolve. They did expect users to use dedupe which is why they even added in that option
Also we are using that exact version 4.2.0 of rollup-plugin-node-resolve https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/servicebus/service-bus/package.json#L95
@ramya0820 @mikeharder

@kurtzeborn
Copy link
Member

kurtzeborn commented Jun 7, 2019

Next step: let's create a minimal repro of this (a depends on b, and both a and b depend on c. c is a third party dependency) and then experiment with fixes in an isolated situation.

Aside: While we currently use rollup, one possible investigation path would be to switch to webpack, parcel or pika. This represents a bunch of work to switch though, so this would need to wait until after the previews are released.

@ramya0820
Copy link
Member Author

Also, please refer to thread on #2809 for more context on what was attempted for EventHubs' browser tests to work with Rush.

For rollup to work with npm 4 more de-dupe entries were required. This is opposite of what was needed for Service Bus, where npm didn't require it and rush did. For Event Hubs, we haven't been able to get a short-term fix either (yet).

@ramya0820
Copy link
Member Author

Looks like something changed with rollup even with Service Bus since I last worked on it.
As I'm working on testing few things related to #3471 / #2809, noticed that even for Service Bus, needing the same additional de-dupe entries to make it work with npm. I don't think the short term workaround for Service Bus works either. We'll need to likely skip running browser tests on CI altogether for now, unless it's with npm I think or some other bundler as discussed earlier today.

cc @ramya-rao-a @bterlson @kurtzeborn @mikeharder @bterlson @KarishmaGhiya

@KarishmaGhiya
Copy link
Contributor

I have created a minimal repro here : https://github.com/KarishmaGhiya/module-duplication-rollup-rush

@ramya0820 ramya0820 self-assigned this Jun 12, 2019
@KarishmaGhiya
Copy link
Contributor

Update: @ramya0820 and I were able to repro the duplication of buffer issue. Here's the latest commit of the PR to the repro here : KarishmaGhiya/module-rollup-buffer@e04a2dd
This is the PR -
https://github.com/KarishmaGhiya/module-rollup-buffer/pull/3/commits

cc: @mikeharder @bterlson

@ramya0820
Copy link
Member Author

ramya0820 commented Jun 15, 2019

Some more notes and things to do next are:

  • The code we have so far at https://github.com/KarishmaGhiya/module-rollup-buffer/pull/3/commits works with npm. And duplication of Buffer in rolled up output was noted (though we only used npm). However, the tests still pass inspite of duplicated entries in rolled up file.
  • Replicate workspace and run only rush commands and see if behavior is same.
  • Modify the way we are using Buffer, instead of the built in Buffer module, we can try using the import { Buffer } from "buffer";
    may also need allowSyntheticDefaultImports in your tsconfig

If the tests do not fail with Rush, then we haven't been able to exactly reproduce the problem.
And we may need to look into usage of Buffer again, and take a closer look at implementation of Rhea.
I think Rhea extends and exposes its own version/wrapper of Buffer as 'Buffer', but need to double check on this.

@ramya0820
Copy link
Member Author

@KarishmaGhiya
Looks like https://github.com/KarishmaGhiya/module-rollup-buffer/pull/3/commits is not configured to run with rush as the standard rush commands - reset-workspace update build are failing with multiple instances of

 ERROR  No package.json (or package.yaml, or package.json5) was found

@KarishmaGhiya
Copy link
Contributor

KarishmaGhiya commented Jun 20, 2019

@ramya0820 The rush reset-workspace is not a standard rush command, it has a script that is configured with our main azure-sdk-for-js repo. I have just the minimal rush commands configured. The build should work on the master. If the build is failing with the PR then it is because of the lib-bee reference in the lib-aaa 's package.json. We need to update it like => lib-bee: 1.0.0

@ramya0820
Copy link
Member Author

Update:
Tests are not failing with rush, had created a separate workspace and cloned the code from PR with above change.
Thus, the issue has not been reproduced taking the current setup of
lib-aaa -> Buffer
lib-bee -> Buffer

We might have to likely try and mimic the concept of exposing global variable in the minimal package ‘C’ repro, as opposed to using ‘Buffer’ package which is a bit more complicated.
Or, use Buffer and try to mimic the way it's being used by Service Bus, Rhea, Rhea-promise and amqp-common.

Agree? Any thoughts on which direction we should go next?
@bterlson @mikeharder @ramya-rao-a

@mikeharder
Copy link
Member

While we don't fully understand why the dedupe is needed, we're pretty sure it's related to how pnpm installs dependencies in a tree rather than flattened, which I believe is exactly what the dedupe option was added for:

rollup/rollup-plugin-node-resolve#201

As long the generated browser bundle looks correct and passes tests, I think it's fine to use the dedupe option.

@bterlson
Copy link
Member

I did some more investigation today; found that there is a bug in the resolve package used by rollup-plugin-node-resolve where it will preserve symlinks in certain situations, even when preserveSymlinks is set to false. A fix is being worked on as we speak, and it may address all of our duplicate buffer issues without needing the dedupe hack (it will certainly address one duplicate, and hopefully the second 🤞).

@mikeharder mikeharder reopened this Jul 30, 2019
@mikeharder
Copy link
Member

Re-opening for tracking until browserify/resolve#196 is resolved

@bterlson
Copy link
Member

bterlson commented Jul 30, 2019

Confirming that with the fix for browserify/resolve#196 and the dedupe config removed, there are no duplicate copies of buffer in the bundle!

mikeharder added a commit to mikeharder/azure-sdk-for-js that referenced this issue Aug 1, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Fixes Azure#3326
mikeharder added a commit to mikeharder/azure-sdk-for-js that referenced this issue Aug 2, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Fixes Azure#3326
mikeharder added a commit to mikeharder/azure-sdk-for-js that referenced this issue Aug 2, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Move buffer to full dependency of service-bus
  - Packages required for browser bundles should be full dependencies
  - Improves customer experience when generating bundles from our packages
- Add dependencies buffer and process to event-hubs
  - Required to generate browser bundle
- Fixes Azure#3326
mikeharder added a commit to mikeharder/azure-sdk-for-js that referenced this issue Aug 5, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Move buffer to full dependency of service-bus
  - Packages required for browser bundles should be full dependencies
  - Improves customer experience when generating bundles from our packages
- Add dependencies buffer and process to event-hubs
  - Required to generate browser bundle
- Fixes Azure#3326
@chradek chradek modified the milestones: Sprint 156, Backlog Aug 6, 2019
mikeharder added a commit to mikeharder/azure-sdk-for-js that referenced this issue Aug 7, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Move buffer to full dependency of service-bus
  - Packages required for browser bundles should be full dependencies
  - Improves customer experience when generating bundles from our packages
- Add dependencies buffer and process to event-hubs
  - Required to generate browser bundle
- Fixes Azure#3326
mikeharder added a commit that referenced this issue Aug 7, 2019
- Update transitive dependency resolve to 1.12.0
  - Fixes issue with symlink resolution which required dedupe workaround
  - browserify/resolve#196
- Depends on rollup-plugin-commonjs@10.0.2
  - Supports preserveSymlinks:false
  - rollup/rollup-plugin-commonjs#400
- Move buffer to full dependency of service-bus
  - Packages required for browser bundles should be full dependencies
  - Improves customer experience when generating bundles from our packages
- Add dependencies buffer and process to event-hubs
  - Required to generate browser bundle
- Fixes #3326
@xirzec xirzec removed this from the Backlog milestone May 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system. Service Bus
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants