Initializers are not allowed in ambient contexts error when installing Blueprint
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_modules/@blueprintjs/core/dist/common/classes.d.ts(4,30):
error TS1039: Initializers are not allowed in ambient contexts.
What's going on? What am I doing wrong?
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.
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.
I had this problem, but for me, updating the local (and global) TypeScript packages did not resolve the problem. Luckily I came across the following article Which version of TypeScript is Visual Studio Using?
In a nutshell, whilst I had updated to TypeScript 2.2, Visual Studio was still referencing version 2.0 in the .csproj
file. I hope this helps someone else with a similar problem.
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
Delete your node-modules folder and do a clean installation.
I had this same issue with a different library than blueprint.js that caused the ts compiler to throw "Initializers are not allowed in ambient contexts" with an index.d.ts
file that looks like this:
declare var identikon_cljs = require('identikon_cljs');
And I was able to get it to compile after adding or setting these properties to true in tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
}
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.
Upgrade typescript to at least 3.1+.
This error is because of node older version of node
You can remove the node version and reinstall it by using the below comand
rm -rf node_modules //For removing
npm install //Install again(Fresh with updated one)
first update package.json with typescript version:3.6.4 and execute command npm i
ReferenceURL : https://stackoverflow.com/questions/42301181/initializers-are-not-allowed-in-ambient-contexts-error-when-installing-blueprint
'programing' 카테고리의 다른 글
datetime 인스턴스가 다른 두 datetime 개체 사이에 있는지 확인합니다. (0) | 2023.06.09 |
---|---|
장고에서 카운트 주석을 위해 객체를 필터링하는 방법은 무엇입니까? (0) | 2023.06.09 |
여러 테스트에 대한 Unit test setUp/tearDown (0) | 2023.06.09 |
임베디드 프로젝트용 C/C++ HTTP 클라이언트 라이브러리 (0) | 2023.06.09 |
부동 소수점 번호 구문 분석:Catch All 알고리즘이 있습니까? (0) | 2023.06.09 |