Skip to content

[Bug]: can not use a local build emitter in tsp 0.67.1 #6625

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

Open
4 tasks done
dolauli opened this issue Mar 24, 2025 · 5 comments · May be fixed by #6883
Open
4 tasks done

[Bug]: can not use a local build emitter in tsp 0.67.1 #6625

dolauli opened this issue Mar 24, 2025 · 5 comments · May be fixed by #6883
Assignees
Labels
bug Something isn't working compiler:core Issues for @typespec/compiler triaged:core
Milestone

Comments

@dolauli
Copy link

dolauli commented Mar 24, 2025

Describe the bug

I used to be able to use a local build emitter to generate code for testing or debugging purposes.

tsp compile ./ --emit c:\Users\<username>\source\autorest.powershell\packages\typespec-powershell

However, after upgrading to TypeSpec/Compiler 0.67.1, I found that it no longer works.

I noticed two major issues

  1. It will report issues as below.
Diagnostics were reported during compilation:

../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/main.tsp:21:1 - error @azure-tools/typespec-azure-resource-manager/single-arm-provider: Only one @armProviderNamespace can be declared in a typespec spec at once.
> 21 | @armProviderNamespace
     | ^^^^^^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/SnapshotResource.tsp:23:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 23 | model SnapshotResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ScopingConfigurationResource.tsp:31:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 31 | model ScopingConfigurationResource
     |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/EvidenceResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 25 | model EvidenceResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of WebhookResource is not registered as an ARM resource type.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of WebhookResource is not registered as an ARM resource type.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/SnapshotResource.tsp:23:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of SnapshotResource is not registered as an ARM resource type.
> 23 | model SnapshotResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
...
  1. The API listServices will return two duplicated services.

Image

Some investigation

The root cause of the issue appears to be the presence of two copies of TypeSpec/Compiler: one in my emitter project and another in my test project.

How to workaround the issue

I can work around the issue by packaging my emitter locally and then installing the emitter package. However, this process is very inconvenient for testing and debugging my emitter.

Reproduction

  1. Install node 20 and rush.
  2. Clone the repo https://github.com/dolauli/autorest.powershell/tree/tspupgrade
  3. Go to the root folder and execute rush update and rush rebuild
  4. Go to tests-upgrade/tests-emitter, edit package.json, remove "@azure-tools/typespec-powershell": "file:../../common/temp/artifacts/packages/azure-tools-typespec-powershell-0.0.1.tgz", and run npm install
  5. Install tsp compiler npm install -g @typespec/compiler@latest
  6. Go to tests-upgrade/tests-emitter/AppComplianceAutomation.Management and run tsp compile ./ --emit c:\Users\<username>\source\autorest.powershell\packages\typespec-powershell or node --inspect-brk 'C:\Users\<username>\source\autorest.powershell\packages\typespec-powershell\node_modules\@typespec\compiler\cmd\tsp.js' compile ./ --emit C:\Users\<username>\source\autorest.powershell\packages\typespec-powershell to debug the code
  7. You will see the issues I mention above

Following the same steps with TSP before version 0.67.1, everything worked fine. You can check out the main branch (which still uses version 0.64.0) of the repo mentioned above to give it a try.

How to workaround

  1. Add "@azure-tools/typespec-powershell": "file:../../common/temp/artifacts/packages/azure-tools-typespec-powershell-0.0.1.tgz", back to the package.json file I mentioned above
  2. Pack the emitter locally rush publish --publish --pack --include-all --tag latest
  3. Go to tests-upgrade/tests-emitter/ and run npm install
  4. Go to tests-upgrade/tests-emitter/AppComplianceAutomation.Management, and run tsp compile ./ --emit @azure-tools/typespec-powershell
  5. Everything works fine

Checklist

@dolauli dolauli added the bug Something isn't working label Mar 24, 2025
@markcowl markcowl added triaged:core compiler:core Issues for @typespec/compiler labels Mar 24, 2025
@markcowl markcowl added this to the [2025] April milestone Mar 24, 2025
@markcowl
Copy link
Contributor

investigate to determine the issue in this sprint

@timotheeguerin
Copy link
Member

timotheeguerin commented Mar 25, 2025

Initial finiding this doesn't repro in a simple case of nested spec inside an emitter

> tsp compile . --emit ~/dev/test/test-nested
TypeSpec compiler v0.67.2

✔ Compiling
✔ test-nested    tsp-output/test-nested/

Compilation completed successfully.

@timotheeguerin
Copy link
Member

timotheeguerin commented Apr 7, 2025

Ok so the issue is that there is multiple instances of libraries getting loaded in those cases

warning incompatible-library: Multiple versions of "@azure-tools/typespec-client-generator-core" library were loaded:
  - Version: "0.53.0" installed at "/Users/timotheeguerin/dev/azsdk/autorest.powershell/tests-upgrade/tests-emitter/node_modules/@azure-tools/typespec-client-generator-core"
  - Version: "0.53.1" installed at "/Users/timotheeguerin/dev/azsdk/autorest.powershell/common/temp/node_modules/.pnpm/@[email protected]_@[email protected]_@t_zrbv43bb4ecg5hztsrjne4irgu/node_modules/@azure-tools/typespec-client-generator-core"

@timotheeguerin
Copy link
Member

Ok so the problem seems to be that somehow the mutated namespace is not part of a realm which cause it to complain about the error above.

@timotheeguerin
Copy link
Member

Ok so the problem is that Relam is treated as a singleton class and keeps track of types added to it but if you load multiple instance of it(like in this example) it will have multiple singleton and not behave as expected.

@timotheeguerin timotheeguerin self-assigned this Apr 7, 2025
@timotheeguerin timotheeguerin linked a pull request Apr 7, 2025 that will close this issue
@markcowl markcowl modified the milestones: [2025] April, [2025] May Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler:core Issues for @typespec/compiler triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants