azure-sdk-for-js icon indicating copy to clipboard operation
azure-sdk-for-js copied to clipboard

@azure/storage-file-datalake is incorrectly importing other packages in the monorepo

Open chenxinyanc opened this issue 8 months ago • 4 comments

  • Package Name: @azure/storage-file-datalake
  • Package Version: 12.22.0
  • Operating system: Microsoft Windows [Version 10.0.26236.5000]
  • [x] nodejs
    • version: 22.2.0
  • [x] browser
    • name/version:
  • [x] typescript
    • version: 5.4.5
  • Is the bug related to documentation in
    • [ ] README.md
    • [ ] source code documentation
    • [ ] SDK API docs on https://docs.microsoft.com

Describe the bug

I see the following error output when using vite to bundle our project. We have enable ESM imports in our project.

X [ERROR] Could not resolve "../../storage-blob/src/utils/cache"

    ../../node_modules/@azure/storage-file-datalake/dist-esm/storage-file-datalake/src/Pipeline.js:14:43:
      14 │ import { getCachedDefaultHttpClient } from "../../storage-blob/src/utils/cache";
         ╵                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "../../storage-blob/src/policies/StorageBrowserPolicyV2"

    ../../node_modules/@azure/storage-file-datalake/dist-esm/storage-file-datalake/src/Pipeline.js:15:37:
      15 │ import { storageBrowserPolicy } from "../../storage-blob/src/policies/StorageBrowserPolicyV2";
         ╵                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "../../storage-blob/src/policies/StorageRetryPolicyV2"

    ../../node_modules/@azure/storage-file-datalake/dist-esm/storage-file-datalake/src/Pipeline.js:16:35:
      16 │ import { storageRetryPolicy } from "../../storage-blob/src/policies/StorageRetryPolicyV2";
         ╵                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "../../storage-blob/src/policies/StorageSharedKeyCredentialPolicyV2"

    ../../node_modules/@azure/storage-file-datalake/dist-esm/storage-file-datalake/src/Pipeline.js:17:49:
      17 │ import { storageSharedKeyCredentialPolicy } from "../../storage-blob/src/policies/StorageSharedKeyCredentialPolicyV2";
         ╵                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To Reproduce Steps to reproduce the behavior: N/A (This error should be there as long as you are consuming the package from outside this monorepo)

Expected behavior

There should be no such error when I'm building the app.

Screenshots image

Additional context

Example code of cause (not exhaustive):

https://github.com/Azure/azure-sdk-for-js/blob/9488fe4bd780306e2f00eaa1509eba20982215f4/sdk/storage/storage-queue/src/Pipeline.ts#L33-L49

I'd appreciate it if you can take the following rules of thumb:

When referencing other packages in your monorepo,

  1. Please refrain from referencing specific file inside any npm package that are not exported from the main / import / exports sections. This is a non-standard operation in earlier versions of node and would be invalid for npm packages with "exports" section defined in package.json.
// do
import { StorageRetryPolicyFactory } from "@azure/storage-blob";
// ⚠️ don't -- this is not valid in packages with `"exports"` section. And most packages are redirecting imports based on environments, configured in their `package.json` file
import { StorageRetryPolicyFactory } from "@azure/storage-blob/src/storage-blob.ts";
import { StorageRetryPolicyFactory } from "@azure/storage-blob/src/dist-esm/storage-blob/src";
import { StorageRetryPolicyFactory } from "@azure/storage-blob/types/latest/storage-blob.d.ts";
  1. Please refrain from importing files that are not inside your package scope -- please do import them in a way so that consumer can also import them in the same way without breaking anything
// do
import { StorageRetryPolicyFactory } from "@azure/storage-blob";
// ⚠️ don't -- this can break, especially if consumer has set up their own custom import mapping
import { StorageRetryPolicyFactory } from "../../storage-blob";

These rules only apply when you are referencing other packages in your monorepo. They do not apply if you are refencing other ts files in the same package.

chenxinyanc avatar Jun 18 '24 06:06 chenxinyanc