Initializers are not allowed in ambient contexts error when installing Blueprint

后端 未结 9 1393
予麋鹿
予麋鹿 2020-12-01 18:19

I\'m trying to use the @blueprintjs/core library in my project. However, when I compile my code, I\'m getting many errors like this:

node_module         


        
相关标签:
9条回答
  • 2020-12-01 18:32

    For windows, to resolve this issue the shortest path is to install Typescript through installer.

    https://www.microsoft.com/en-us/download/details.aspx?id=48593

    0 讨论(0)
  • 2020-12-01 18:33

    As of @blueprintjs/core@1.7.0, Blueprint is now compiled using TypeScript 2.1. With this new version of TypeScript, initializers are added to the emitted typings for constants.

    So before, a line of the emitted classes.d.ts looked like this:

    export declare const ACTIVE: string;
    

    It now looks like this and includes an initializer:

    export declare const ACTIVE = "pt-active";
    

    This new syntax in declaration files makes old versions of the compiler unhappy. To make the error go away, you'll need to make sure you're compiling your project with at least TypeScript 2.1.

    0 讨论(0)
  • 2020-12-01 18:35

    The problem is that you are writing code in a d.ts file. You should only be writing types in these "ambient" files. Things like initializing variables, writing functions, etc should not be done in "ambient" files.

    0 讨论(0)
  • 2020-12-01 18:42

    Upgrade typescript to at least 3.1+.

    0 讨论(0)
  • 2020-12-01 18:47

    first update package.json with typescript version:3.6.4 and execute command npm i

    0 讨论(0)
  • 2020-12-01 18:48

    I've been having this issue. Needed to download the latest version of typescript from typescript website and make sure 'use latest version' is selected in visual studio project properties.

    0 讨论(0)
提交回复
热议问题