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

[storage-blob] cannot import in to commonjs project #31695

Open
2 of 6 tasks
andyryan opened this issue Nov 8, 2024 · 5 comments
Open
2 of 6 tasks

[storage-blob] cannot import in to commonjs project #31695

andyryan opened this issue Nov 8, 2024 · 5 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@andyryan
Copy link

andyryan commented Nov 8, 2024

  • @azure/storage-blob:
  • 12.25.0:
  • Linux:
  • nodejs
    • 20.18:
  • browser
    • name/version:
  • typescript
    • 5.2:
  • Is the bug related to documentation in

Describe the bug

We have a Typescript project which outputs CommonJS JS. We are trying to use the storage-blob sdk but running in to import issues.

We cannot simply change our project to an ES module as this caused a myriad of other dependencies to break (and much of the current NPM landscape is still CommonJS so I would expect MS to be able to support this).

We tried to import @azure/storage-blob in a few ways:

  1. standard Typescript import ... from: gave an error that import cannot be used outside of a ES module. Somewhat expected given the typescript documentation. So on to attempt 2
  2. javascript require: create a .js file instead of .ts, use require const { BlobServiceClient } = require("@azure/storage-blob") as per javascript documentation.

This however caused the following error:

{"level":"error","message":"Express encountered an error Unexpected token 'export'","service":"api-v2","stack":"/..../node_modules/@azure/storage-blob/dist-esm/storage-blob/src/generated/src/models/index.js:9\nexport var KnownEncryptionAlgorithmType;\n^^^^^^\n\nSyntaxError: Unexpected token 'export'\n    at wrapSafe (node:internal/modules/cjs/loader:1378:20)\n    at Module._compile (node:internal/modules/cjs/loader:1428:41)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)\n    at Object.require.extensions.<computed> [as .js] (/..../node_modules/ts-node/src/index.ts:1608:43)\n    at Module.load (node:internal/modules/cjs/loader:1288:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)\n    at Module.require (node:internal/modules/cjs/loader:1311:19)\n    at require (node:internal/modules/helpers:179:18)\n    at tryToRequire (/..../node_modules/src/util/ImportUtils.ts:21:17)\n    at importOrRequireFile (/.../node_modules/src/util/ImportUtils.ts:35:25)","timestamp":"2024-11-08 15:52:13"}

To Reproduce
Steps to reproduce the behavior:

  1. create a commonJS typescript project
  2. Create a .js file
  3. import storage blob with require const { BlobServiceClient } = require("@azure/storage-blob")

Expected behavior
@azure/storage-blob package is successfully imported and usable within the file

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@jeremymeng
Copy link
Member

Thanks for the report! It is strange that CJS would reach into the dist-esm/ directory:

node_modules/@azure/storage-blob/dist-esm/storage-blob/src/generated/src/models/index.js

@jeremymeng
Copy link
Member

@andyryan we expect CJS to work. Could you please try to see if any of the samples here works in your environment? https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/samples/v12/javascript

I just verified that listing blobs working fine with CJS on NodeJS v20.18.0

@jeremymeng jeremymeng added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Nov 13, 2024
@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Nov 13, 2024
Copy link

Hi @andyryan. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Copy link

Hi @andyryan, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@github-actions github-actions bot added the no-recent-activity There has been no recent activity on this issue. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

3 participants