Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
179 stars 75 forks source link

TypeError: Cannot read properties of undefined (reading 'enums') #2729

Closed HarshaNalluru closed 3 months ago

HarshaNalluru commented 3 months ago

PR: https://github.com/Azure/azure-sdk-for-js/pull/30373 Typespec: https://github.com/Azure/azure-rest-api-specs-pr/pull/17637 Command used: tsp-client update --local-spec-repo /workspaces/azure-sdk-for-js/sdk/documentintelligence/typespec Updated emitter-package.json to

{
  "name": "typescript-emitter-package",
  "main": "dist/src/index.js",
  "dependencies": {
    "@azure-tools/typespec-ts": "0.31.0",
    "@azure-tools/typespec-azure-core": "0.44.0",
    "@azure-tools/typespec-autorest": "0.44.1",
    "@azure-tools/typespec-client-generator-core": "0.44.2",
    "@azure-tools/typespec-azure-resource-manager": "0.44.0",
    "@azure-tools/typespec-azure-rulesets": "0.44.0",
    "@typespec/compiler": "0.58.1",
    "@typespec/http": "0.58.0",
    "@typespec/rest": "0.58.0",
    "@typespec/versioning": "0.58.0"
  }
}

Hits the following error..

Resolved path: /workspaces/azure-sdk-for-js/sdk/documentintelligence/ai-document-intelligence-rest/TempTypeSpecFiles/DocumentIntelligence/node_modules/@typespec/compiler
Compiling tsp using @azure-tools/typespec-ts...
ExternalError: Emitter "@azure-tools/typespec-ts" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.typescript/issues

TypeError: Cannot read properties of undefined (reading 'enums')
    at provideSdkTypes (file:///workspaces/azure-sdk-for-js/sdk/documentintelligence/ai-document-intelligence-rest/TempTypeSpecFiles/DocumentIntelligence/node_modules/@azure-tools/typespec-ts/dist/src/framework/hooks/sdkTypes.js:31:38)
    at Object.$onEmit [as emitFunction] (file:///workspaces/azure-sdk-for-js/sdk/documentintelligence/ai-document-intelligence-rest/TempTypeSpecFiles/DocumentIntelligence/node_modules/@azure-tools/typespec-ts/dist/src/index.js:45:5)
    at runEmitter (file:///workspaces/azure-sdk-for-js/sdk/documentintelligence/ai-document-intelligence-rest/TempTypeSpecFiles/DocumentIntelligence/node_modules/@typespec/compiler/dist/src/core/program.js:452:27)
    at compile (file:///workspaces/azure-sdk-for-js/sdk/documentintelligence/ai-document-intelligence-rest/TempTypeSpecFiles/DocumentIntelligence/node_modules/@typespec/compiler/dist/src/core/program.js:132:15)
    at async compileTsp (file:///usr/local/share/nvm/versions/node/v19.7.0/lib/node_modules/@azure-tools/typespec-client-generator-cli/dist/typespec.js:76:21)
    at async generate (file:///usr/local/share/nvm/versions/node/v19.7.0/lib/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:196:5)
    at async main (file:///usr/local/share/nvm/versions/node/v19.7.0/lib/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:296:13)

--------------------------------------------------
Library Version                0.31.0
TypeSpec Compiler Version      0.58.1
--------------------------------------------------
HarshaNalluru commented 3 months ago

The following version set works. Thanks for debugging @joheredi

{
  "name": "typescript-emitter-package",
  "main": "dist/src/index.js",
  "dependencies": {
    "@azure-tools/typespec-ts": "0.31.0-alpha.20240805.1",
    "@azure-tools/typespec-azure-core": "0.44.0",
    "@azure-tools/typespec-autorest": "0.44.1",
    "@azure-tools/typespec-client-generator-core": "0.44.3",
    "@azure-tools/typespec-azure-resource-manager": "0.44.0",
    "@azure-tools/typespec-azure-rulesets": "0.44.0",
    "@typespec/compiler": "0.58.1",
    "@typespec/http": "0.58.0",
    "@typespec/rest": "0.58.0",
    "@typespec/versioning": "0.58.0"
  }
}