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

[ai-document-intelligence] Loading from an ESM module still doesn't seem to work fine. Still loads CJS #30020

Open
1 of 6 tasks
nicu-chiciuc opened this issue Jun 12, 2024 · 2 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Form Recognizer customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that RestLevelClient

Comments

@nicu-chiciuc
Copy link

nicu-chiciuc commented Jun 12, 2024

  • Package Name: @azure-rest/ai-document-intelligence
  • Package Version: 1.0.0-beta.2
  • Operating system: macOS 14.4.1 (23E224)
  • nodejs
    • version: v18.18.2
  • browser
    • name/version:
  • typescript
    • version:
  • Is the bug related to documentation in

Describe the bug

I'm using this tsconfig.json

{
  "extends": ["tsconfig/base-esm.json"],
  "exclude": ["node_modules"],
  "include": ["src", "scripts"],

  "compilerOptions": {
    "lib": ["ESNext"],

    "declaration": false,
    "declarationMap": false,

    "sourceMap": true,

    "checkJs": false,
    "allowJs": false,

    "rootDir": "./src",
    "outDir": "./dist",
  }
}
// base-esm.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Pure ESM",
  "extends": "./base.json",
  "compilerOptions": {
    "lib": ["ESNext"],

    "module": "NodeNext",
    "target": "esnext",
    "moduleResolution": "NodeNext",

    "checkJs": true
  }
}

The TS files are translated directly to ESM without converting them to commonjs, since Node supports running ESM.

When trying to import the default function from '@azure-rest/ai-document-intelligence' I get a TS error if I want to call it directly:

Screenshot 2024-06-12 at 16 59 27

using DocumentIntelligence.default() fixes this issue.

Screenshot 2024-06-12 at 16 59 48

Since this is a monorepo, another projects imports this Node app (just for the types). And that causes issues, since that project is using Next.js, and as such is not yet converted to type: "module".

I've ran the Node project using NODE_DEBUG=esm to figure out which file is actually imported.

ESM 34908: Loading CJSModule file:///Users/nicu/dev/robo/robo-turbo/node_modules/.pnpm/@azure-rest+ai-document-intelligence@1.0.0-beta.2/node_modules/@azure-rest/ai-document-intelligence/dist/index.js

it seems that it's still loading the CJS file instead the one from /dist-esm/.

A simple solution would be to also provide a non-default export so these issues don't appear.

To Reproduce
Steps to reproduce the behavior:

  1. Import the package in an ESM project.

Expected behavior
I expect to be able to import the project in an ESM project

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
given above

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 12, 2024
@xirzec xirzec added Client This issue points to a problem in the data-plane of the library. Cognitive - Form Recognizer RestLevelClient labels Jun 12, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 12, 2024
@xirzec
Copy link
Member

xirzec commented Jun 12, 2024

@mpodwysocki will this be fixed by migration to ESM/tshy?

/cc @joheredi

@mpodwysocki
Copy link
Member

@xirzec Yes, this will be fixed with a tshy migration

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. Cognitive - Form Recognizer customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that RestLevelClient
Projects
None yet
Development

No branches or pull requests

4 participants