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

Rollup is embedding all dependencies in lib after upgrade to v16 #17660

Closed
1 of 4 tasks
minuz opened this issue Jun 17, 2023 · 4 comments
Closed
1 of 4 tasks

Rollup is embedding all dependencies in lib after upgrade to v16 #17660

minuz opened this issue Jun 17, 2023 · 4 comments
Labels
outdated scope: bundlers Issues related to webpack, rollup stale type: bug

Comments

@minuz
Copy link

minuz commented Jun 17, 2023

Current Behavior

Before upgrading from v15.x to latest (16.3.2) the libs assets would not embed any dependencies into the lib itself. The result was a smaller lib package. After the migration, each lib is now embedding all its dependencies, including node_modules dependencies into the lib index.js
When importing into apps external to the monorepo, it breaks with multiple issues. Mostly because we do have some legacy apps that are not fully upgraded to latest version of react and other dependencies. Up to this point it was all working fine.

Expected Behavior

The compilation/bundling should've remained the same.

GitHub Repo

https://github.com/minuz/rollup-issue

Steps to Reproduce

  1. Clone repo above
  2. Run nx run-many --target=build --all
  3. Compare the build assets from the 2 libs

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 16.20.0
   OS     : darwin arm64
   yarn   : 1.22.19
   Hasher : Native
   
   nx (global)        : 16.3.2
   nx                 : 16.3.2
   @nx/js             : 16.3.2
   @nx/jest           : 16.3.2
   @nx/linter         : 16.3.2
   @nx/workspace      : 16.3.2
   @nx/cypress        : 16.3.2
   @nx/devkit         : 16.3.2
   @nx/eslint-plugin  : 16.3.2
   @nx/node           : 16.3.2
   @nx/plugin         : 16.3.2
   @nx/react          : 16.3.2
   @nx/rollup         : 16.3.2
   @nx/storybook      : 16.3.2
   @nrwl/tao          : 16.3.2
   @nx/vite           : 16.3.2
   @nx/web            : 16.3.2
   @nx/webpack        : 16.3.2
   nx-cloud           : 16.0.5
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   @jscutlery/semver : 3.0.0
   ---------------------------------------

Failure Logs

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Upon some digging, I managed to get the expected results by manually adding the dependent libraries into the lib package.json. However, this is not a sustainable solution as it requires to manually add dependencies to each library and we have plenty! More importantly, it relies on manual intervention and diligence from each developer to ensure the dependencies are correctly set on package.json. We have been relying on Rollup to automatically set the dependencies and peer dependencies during compilation time.

I'm hoping there's some configuration that I missed that would allow that to still happen without having to manually add dependencies into each lib.

On the repo above, I created two libs.
They are essentially the same code (and what it does is really not important). They use axios to fetch data on load.
The compiled library will have the is-even with axios code embedded in it and the is-odd will only have the code from the lib itself, which is what I'd expect.

The setup difference is in the package.json where on is-odd I manually add axios as dependency.
On nx 15, I used to be able to let rollup deal with that by itself so I wouldn't need to manually declare anything on the package.json

Any insights are greatly appreciated.

@JosefBredereck
Copy link
Contributor

This seems to be a general issue; see #10227

@minuz
Copy link
Author

minuz commented Jul 18, 2023

@JosefBredereck thanks for linking them up. For the most part, it was just an inconvenience thing, but I'm starting to have some real issues with this.

We have a lib where we customise Axios in order to do common things like append some custom headers and add some global error handling within the interceptors, etc...

With apps that are within the repo, no dramas. But we started to have some issues with apps that are not part of the repo and upon investigation, the culprit seems to be related to the fact that with rollup, it's embedding the axios in it and it seems to be conflicting with axios version from the app itself.

As a test, I created the lib using vite bundler and compared the output with the rollup.
On the left it's the same lib using Vite and on the right, the original lib with rollup. The difference is brutal and more important, the right one doesn't work on the legacy apps =(
image

If push comes to shove, I'll migrate everything to vite, but that will be quite the hassle and I'm trying to avoid doing that...

NOTE: The external prop doesn't seems to work

      "executor": "@nx/rollup:rollup",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/shared/util/custom-axios",
        "tsConfig": "libs/shared/util/custom-axios/tsconfig.lib.json",
        "project": "libs/shared/util/custom-axios/package.json",
        "entryFile": "libs/shared/util/custom-axios/src/index.ts",
        "external": ["axios", "react", "react-dom", "react/jsx-runtime"],
        "rollupConfig": ["@nx/react/plugins/bundle-rollup", "tools/getRollupOptions.js"],
        "compiler": "babel",
        "assets": [
          {
            "glob": "libs/shared/util/custom-axios/README.md",
            "input": ".",
            "output": "."
          }
        ]
      }
    },

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

github-actions bot commented Mar 1, 2024

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup stale type: bug
Projects
None yet
Development

No branches or pull requests

3 participants