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

CLI: Rollup does not build some packages correctly #6288

Closed
rmanny opened this issue Jun 30, 2021 · 3 comments · Fixed by #9987
Closed

CLI: Rollup does not build some packages correctly #6288

rmanny opened this issue Jun 30, 2021 · 3 comments · Fixed by #9987
Labels
bug Something isn't working cli CLI tool for plugins and apps help wanted Help/Contributions wanted from community members

Comments

@rmanny
Copy link
Contributor

rmanny commented Jun 30, 2021

I have been having issues with using AWS SDK v3 from the backend, since it depends on uuidjs. uuidjs targets browser by default, and must explicitly use a exportConditions: ['node'] flag to build the correct version. If I am understanding the Backstage code correctly, this is missing from the rollup args used in the bundler.

This Rollup issue is propagating into Backstage since users do not have control over the rollup config (at least to my knowledge).

Expected Behavior

When the backend is built, it should select the node version of uuidjs.

Current Behavior

The browser version is built instead, which leads to this error message from AWS SDK.

2021-06-30T21:51:32.370Z aws-integration error Error: s3Client.getObject failed, Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported type=plugin
2021-06-30T21:51:32.370Z aws-integration error crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported type=plugin stack=Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported
    at rng (/usr/src/app/packages/backend/dist/index.cjs.js:14098:13)
    at v4 (/usr/src/app/packages/backend/dist/index.cjs.js:14141:52)
    at StandardRetryStrategy.<anonymous> (/usr/src/app/packages/backend/dist/index.cjs.js:14252:69)
    at step (/usr/src/app/packages/backend/dist/index.cjs.js:3784:23)
    at Object.next (/usr/src/app/packages/backend/dist/index.cjs.js:3765:53)
    at fulfilled (/usr/src/app/packages/backend/dist/index.cjs.js:3755:58)

From looking at the uuidjs code, this error is only possible on the browser version.

Possible Solution

I am a total rollup novice, but I think it would be possible to globally configure exportConditions: ['node'] in the backend/bundler code. If I am misunderstanding how that flag works, it may be a question of analyzing the package.json of each module and checking for a "node" export. Kind of a pain so I hope the first one works.

For now I am using a crypto polyfill, which works just fine, but this issue really stumped me for a while and I would like to save some future devs the frustration.

Steps to Reproduce

  1. Create a Backstage project with uuidjs as a dependency
  2. Build a backend docker image
  3. Try calling the uuid.v4() function from within the express router

Context

Using AWS SDK v3. See error message above.

Here's the package.json for uuidjs for more context.

Your Environment

  • NodeJS Version (v14):
@rmanny rmanny added the bug Something isn't working label Jun 30, 2021
@cruikshj
Copy link

I am experiencing the same issue, but with the Microsoft Graph packages.

@Rugvip Rugvip added cli CLI tool for plugins and apps help wanted Help/Contributions wanted from community members labels Aug 5, 2021
@jrusso1020
Copy link
Contributor

I was able to get past this by adding the uuid package directly to the backend package.json

@Rugvip
Copy link
Member

Rugvip commented Mar 4, 2022

I believe this is due to packages not being externalized because they're not added as a dependency of the package. Our rollup build is intended to only touch code in the package itself, and not traverse into dependencies. It's why we have the this lint rule in our standard lint config: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md

This issue is a bit too easy to hit though, and tricky to debug. I'll look into if we can flip the externalization around to make things more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli CLI tool for plugins and apps help wanted Help/Contributions wanted from community members
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants