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

Could not resolve "../package.json" on v5.20.1 #1934

Closed
dryror opened this issue May 17, 2022 · 12 comments · Fixed by #1936 or #1941
Closed

Could not resolve "../package.json" on v5.20.1 #1934

dryror opened this issue May 17, 2022 · 12 comments · Fixed by #1936 or #1941
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dryror
Copy link

dryror commented May 17, 2022

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

  1. Is this a client library issue or a product issue?
    library issue

  2. Did someone already solve this?
    Not that I can find

  3. Do you have a support contract?
    No

Environment details

  • OS: macOS
  • Node.js version: 14 and 16
  • npm version: 6.14.16 and 8.5.5
  • @google-cloud/storage version: v5.20.1

Steps to reproduce

  1. Install @google-cloud/storage and use it as a dependency in your project
  2. Package your project with esbuild
  3. See that it fails with the following errors:
✘ [ERROR] Could not resolve "../package.json"

    node_modules/@google-cloud/storage/build/src/storage.js:384:34:
      384 │             packageJson = require('../package.json');
          ╵                                   ~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "../../package.json"

    node_modules/@google-cloud/storage/build/src/nodejs-common/util.js:37:26:
      37 │     packageJson = require('../../package.json');
         ╵                           ~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] Could not resolve "../package.json"

    node_modules/@google-cloud/storage/build/src/gcs-resumable-upload.js:37:26:
      37 │     packageJson = require('../package.json');
         ╵                           ~~~~~~~~~~~~~~~~~

I am using firebase-admin which has @google-cloud/storage as a dependency. When I pin @google-cloud/storage to 5.19.4 I can package my app fine with esbuild. When it is updated to v5.20.1 it starts to fail with the above error.

@dryror dryror added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 17, 2022
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label May 17, 2022
@faradaytrs
Copy link

Same here

@timdp
Copy link

timdp commented May 17, 2022

Also experiencing this.

Couldn't the complected fallthrough be avoided by having the same directory depth in both cases?

@ddelgrosso1 ddelgrosso1 self-assigned this May 17, 2022
@ddelgrosso1 ddelgrosso1 added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels May 17, 2022
@ddelgrosso1
Copy link
Contributor

Hello all, thank you for bringing this to our attention. I believe this should now be resolved in 5.20.2. If you are still seeing issues please feel free to reopen.

@timdp
Copy link

timdp commented May 17, 2022

As I wrote under #1936, I think that patch is neither necessary nor relevant.

@ddelgrosso1
Copy link
Contributor

Thanks @timdp digging deeper into why this may be causing esbuild problems.

@faradaytrs
Copy link

faradaytrs commented May 18, 2022

Now there is problem in runtime, please reopen
"Error: Unable to find package.json",
" at Object.getPackageJSON (/var/task/src/image.js:69669:13)",
" at node_modules/.pnpm/@Google-Cloud+storage@5.20.3/node_modules/@google-cloud/storage/build/src/nodejs-common/util.js (/var/task/src/image.js:72893:30)",
" at __require (/var/task/src/image.js:40:50)",
" at node_modules/.pnpm/@Google-Cloud+storage@5.20.3/node_modules/@google-cloud/storage/build/src/nodejs-common/service.js (/var/task/src/image.js:73300:18)",
" at __require (/var/task/src/image.js:40:50)",
" at node_modules/.pnpm/@Google-Cloud+storage@5.20.3/node_modules/@google-cloud/storage/build/src/nodejs-common/index.js (/var/task/src/image.js:73700:21)",
" at __require (/var/task/src/image.js:40:50)",
" at node_modules/.pnpm/@Google-Cloud+storage@5.20.3/node_modules/@google-cloud/storage/build/src/bucket.js (/var/task/src/image.js:89418:27)",
" at __require (/var/task/src/image.js:40:50)",
" at node_modules/.pnpm/@Google-Cloud+storage@5.20.3/node_modules/@google-cloud/storage/build/src/index.js (/var/task/src/image.js:90189:20)"

@ddelgrosso1 ddelgrosso1 reopened this May 18, 2022
@ddelgrosso1
Copy link
Contributor

@faradaytrs I want to confirm that this is with an application built utilizing esbuild is that correct? If so, would you be able to provide what the configuration looks like?

@ddelgrosso1
Copy link
Contributor

Just a quick update, I have been digging into the differences in esbuild output between 5.19.4 and 5.20.3. Previously esbuild was able to inline the contents of package.json and wrap it in an internal function. When we made the pathing more "dynamic" in nature it appears esbuild is no longer able to do the same. While @timdp's suggestion may potentially fix this it would require some more build changes. We are currently looking at other possible alternatives.

@timdp
Copy link

timdp commented May 18, 2022

I guess the alternative would be an esbuild patch that inlines top-level try { require(); ... }. That seems pretty specific though and it's ultimately just working around (to my best knowledge) unnecessary complexity.

@ddelgrosso1
Copy link
Contributor

After investigating the issue was the result of a change we made to support running unit tests directly in TypeScript. This caused us to move to dynamic requires for package.json. This caused esbuild to not be able to analyze / inline the package.json any more. We have reverted the change and gone back to a single require call that should again allow esbuild to inline the file. This will be released with 5.20.4. I am going to leave this issue open in the meantime.

@ddelgrosso1
Copy link
Contributor

Update: 5.20.4 has been published.

@timdp
Copy link

timdp commented May 19, 2022

Seems fine again. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
5 participants