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

An accessor cannot be declared in an ambient context. #3513

Closed
ghiscoding opened this issue Nov 30, 2019 · 16 comments
Closed

An accessor cannot be declared in an ambient context. #3513

ghiscoding opened this issue Nov 30, 2019 · 16 comments

Comments

@ghiscoding
Copy link

ghiscoding commented Nov 30, 2019

Regression

Potential Commit/PR that introduced the regression**

I don't know what introduced this issue, the only thing I found is this Stack Overflow question which says this

so presumably sequelize was compiled with typescript 3.7 and emits definition files that previous versions don't understand. So you'll need to upgrade to typescript 3.7 or use an earlier version of sequelize.

But I'm already using TypeScript version 3.7.2, so I'm not sure where this error comes from and how to fix it.

Describe the regression

I get a bunch of TypeScript lint errors after updating to latest NestJS 6.10.4 (from 6.10.1). I tried going back to ~6.10.1 but I still get the error. I tried upgrading my NodeJS version 10 to 12 but still have the same issue. I also tried using TypeScript version 3.6.3 instead of 3.7.2 but still the issue persist.

I found this bugfix in another library, which removes the get prefix in *.d.ts files, the change is that lib is the following

-  get size(): Size;
+  size: Size;

If I click and follow the link on the first @nestjs/common/http/http.service.d.ts:13:9 error, I do see the get in that d.ts file

export declare class HttpService {
   //...
   get axiosRef(): AxiosInstance;
}

So it seems that the d.ts Type files are not compiled properly? If I manually remove the get from axiosRef(): AxiosInstance;, I get 1 less error. So that seems to be the issue.

export declare class HttpService {
   //...
-   get axiosRef(): AxiosInstance;
+   axiosRef(): AxiosInstance;
}

After manually editing every d.ts file causing errors and removing their get/set I'm back to working again, so that seems to be the issue.

Input Code

Expected behavior/code

Environment


Nest version: 6.10.1 -> 6.10.4

For Tooling issues:
- Node version: 12.13.1
- TypeScript version: 3.7.2
- Platform:  Windows

Others:

The errors I get are the following

node_modules/@nestjs/common/http/http.service.d.ts:13:9 - error TS1086: An accessor cannot be declared in an ambient context.
13     get axiosRef(): AxiosInstance;
           ~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:21:9 - error TS1086: An accessor cannot be declared in an ambient context.
21     set httpAdapter(httpAdapter: T);
           ~~~~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:28:9 - error TS1086: An accessor cannot be declared in an ambient context.
28     get httpAdapter(): T;
           ~~~~~~~~~~~

node_modules/@nestjs/core/injector/container.d.ts:16:9 - error TS1086: An accessor cannot be declared in an ambient context.
16     get applicationConfig(): ApplicationConfig | undefined;
           ~~~~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:32:9 - error TS1086: An accessor cannot be declared in an ambient context.
32     get id(): string;
           ~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:33:9 - error TS1086: An accessor cannot be declared in an ambient context.
33     set instance(value: T);
           ~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:34:9 - error TS1086: An accessor cannot be declared in an ambient context.
34     get instance(): T;
           ~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:35:9 - error TS1086: An accessor cannot be declared in an ambient context.
35     get isNotMetatype(): boolean;
           ~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:36:9 - error TS1086: An accessor cannot be declared in an ambient context.
36     get isTransient(): boolean;
           ~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:20:9 - error TS1086: An accessor cannot be declared in an ambient context.
20     get id(): string;
           ~~

node_modules/@nestjs/core/injector/module.d.ts:21:9 - error TS1086: An accessor cannot be declared in an ambient context.
21     get scope(): Type[];
           ~~~~~

node_modules/@nestjs/core/injector/module.d.ts:22:9 - error TS1086: An accessor cannot be declared in an ambient context.
22     get providers(): Map>;
           ~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:23:9 - error TS1086: An accessor cannot be declared in an ambient context.
23     get imports(): Set;
           ~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:27:9 - error TS1086: An accessor cannot be declared in an ambient context.
27     get relatedModules(): Set;
           ~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:31:9 - error TS1086: An accessor cannot be declared in an ambient context.
31     get components(): Map>;
           ~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:35:9 - error TS1086: An accessor cannot be declared in an ambient context.
35     get routes(): Map>;
           ~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:36:9 - error TS1086: An accessor cannot be declared in an ambient context.
36     get injectables(): Map>;
           ~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:37:9 - error TS1086: An accessor cannot be declared in an ambient context.
37     get controllers(): Map>;
           ~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:38:9 - error TS1086: An accessor cannot be declared in an ambient context.
38     get exports(): Set;
           ~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:39:9 - error TS1086: An accessor cannot be declared in an ambient context.
39     get instance(): NestModule;
           ~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:40:9 - error TS1086: An accessor cannot be declared in an ambient context.
40     get metatype(): Type;
           ~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:41:9 - error TS1086: An accessor cannot be declared in an ambient context.
41     get distance(): number;
           ~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:42:9 - error TS1086: An accessor cannot be declared in an ambient context.
42     set distance(value: number);
@ghiscoding ghiscoding added needs triage This issue has not been looked into type: bug 😭 labels Nov 30, 2019
@ghiscoding
Copy link
Author

ghiscoding commented Nov 30, 2019

Also if it helps, here is my tsconfig.json file

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "esnext",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

@kamilmysliwiec
Copy link
Member

Please, provide a minimal repository which reproduces your issue.

@kamilmysliwiec kamilmysliwiec added needs clarification and removed needs triage This issue has not been looked into type: bug 😭 labels Dec 1, 2019
@ghiscoding
Copy link
Author

I tried replicating the issue on my other desktop and it was all working, however I had to install NestJS CLI because it was never installed on that computer. That made me think to update the CLI on the computer I had issue with... and after updating to latest NestJS CLI, the error is gone.

Since I can't replicate after updating NestJS CLI, I'll close the issue
Thanks

@kotuadam
Copy link

kotuadam commented Dec 1, 2019

I am having the same problem... Fresh install and updating cli does not solve it. Operating system is Mac OS

@ghiscoding
Copy link
Author

@kotuadam
There's couple things you can try, the first one is to delete the entire node_modules and also the yarn/npm lock files, then re-install everything. The other options would be to see which TypeScript version you're using, I'm on 3.7.2 which is the latest.

@syukirah
Copy link

syukirah commented Dec 2, 2019

I'm also facing the same problem. Its working in my local but failed when i deploy to server (openshift)

@Figments
Copy link

Figments commented Dec 2, 2019

Same issue here.

@whitebyte
Copy link

This issue is relevant, please reopen. I just encountered the same error while trying to update from 6.7.2 to 6.10.4. Managed to resolve it somehow after wiping node_modules and doing npm upgrade, but no idea how to reproduce it.

@kamilmysliwiec kamilmysliwiec reopened this Dec 2, 2019
@kamilmysliwiec
Copy link
Member

It sounds like a breaking change introduced in TypeScript microsoft/TypeScript#33939

@jeffminsungkim
Copy link
Contributor

@nestjs/core v6.10.4

Screenshot 2019-12-02 17 53 00

@nestjs/core v6.10.2

Screenshot 2019-12-02 18 05 10

Currently using Typescript v3.5.1

@Figments
Copy link

Figments commented Dec 2, 2019

Switching entirely to Yarn seems to have fixed the issue for me, though the reason why NPM seemed to be the cause of my specific issues is beyond me.

@franzos
Copy link

franzos commented Dec 2, 2019

I've been able to resolve this, by manually upgrading typescript.

package.json: "typescript": "3.4.3" to "typescript": "3.7.2"

finally, cleared out, and re-installed everything:

rm -r node_modules; rm package-lock.json
npm install

@kamilmysliwiec
Copy link
Member

I've published v6.10.5 release with a downgraded TypeScript to 3.6.4 version. If you are facing this issue, please, update to the latest version of @nestjs. Hopefully, TypeScript team will solve this shortly

@kotuadam
Copy link

kotuadam commented Dec 2, 2019

latest push fixed everything for me

@ghost
Copy link

ghost commented Dec 10, 2019

Facing this issue when adding @nestjs/ng-universal to Angular 8 project.
Have tried with latest Nestjs version 6.10.9 and with Typescript 3.5.3. I am not able to upgrade typescript to newer version, Angular CLI does not support > 3.6.0

Application starts up normal but errors persists.

`10% building 3/3 modules 0 activenode_modules/@nestjs/common/http/http.service.d.ts:13:9 - error TS1086: An accessor cannot be declared in an ambient context.

13 get axiosRef(): AxiosInstance;
~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:21:9 - error TS1086: An accessor cannot be declared in an ambient context.

21 set httpAdapter(httpAdapter: T);
~~~~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:28:9 - error TS1086: An accessor cannot be declared in an ambient context.

28 get httpAdapter(): T;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/container.d.ts:18:9 - error TS1086: An accessor cannot be declared in an ambient context.

18 get applicationConfig(): ApplicationConfig | undefined;
~~~~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:32:9 - error TS1086: An accessor cannot be declared in an ambient context.

32 get id(): string;
~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:33:9 - error TS1086: An accessor cannot be declared in an ambient context.

33 set instance(value: T);
~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:34:9 - error TS1086: An accessor cannot be declared in an ambient context.

34 get instance(): T;
~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:35:9 - error TS1086: An accessor cannot be declared in an ambient context.

35 get isNotMetatype(): boolean;
~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:36:9 - error TS1086: An accessor cannot be declared in an ambient context.

36 get isTransient(): boolean;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:20:9 - error TS1086: An accessor cannot be declared in an ambient context.

20 get id(): string;
~~

node_modules/@nestjs/core/injector/module.d.ts:21:9 - error TS1086: An accessor cannot be declared in an ambient context.

21 get scope(): Type[];
~~~~~

node_modules/@nestjs/core/injector/module.d.ts:22:9 - error TS1086: An accessor cannot be declared in an ambient context.

22 get providers(): Map<any, InstanceWrapper>;
~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:23:9 - error TS1086: An accessor cannot be declared in an ambient context.

23 get imports(): Set;
~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:27:9 - error TS1086: An accessor cannot be declared in an ambient context.

27 get relatedModules(): Set;
~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:31:9 - error TS1086: An accessor cannot be declared in an ambient context.

31 get components(): Map<string, InstanceWrapper>;
~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:35:9 - error TS1086: An accessor cannot be declared in an ambient context.

35 get routes(): Map<string, InstanceWrapper>;
~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:36:9 - error TS1086: An accessor cannot be declared in an ambient context.

36 get injectables(): Map<string, InstanceWrapper>;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:37:9 - error TS1086: An accessor cannot be declared in an ambient context.

37 get controllers(): Map<string, InstanceWrapper>;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:38:9 - error TS1086: An accessor cannot be declared in an ambient context.

38 get exports(): Set<string | symbol>;
~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:39:9 - error TS1086: An accessor cannot be declared in an ambient context.

39 get instance(): NestModule;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:40:9 - error TS1086: An accessor cannot be declared in an ambient context.

40 get metatype(): Type;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:41:9 - error TS1086: An accessor cannot be declared in an ambient context.

41 get distance(): number;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:42:9 - error TS1086: An accessor cannot be declared in an ambient context.

42 set distance(value: number);
~~~~~~~~

[21:58:20] Found 23 errors. Watching for file changes.`

@kamilmysliwiec
Copy link
Member

Lets track this here microsoft/TypeScript#33939

@nestjs nestjs locked as too heated and limited conversation to collaborators Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants