Please specify what version of the library you are using: [ 1.2.3 ]
Please specify what version(s) of SharePoint you are targeting: [ 2013 ]
I'm trying to use @pnp/sp in an Angular 6 project.
When i do an import of import { sp } from "@pnp/sp"; i get the following build error from the Angular CLI:
I receive the following error from the Angular cli:
ERROR in node_modules/@pnp/sp/src/search.d.ts(473,33): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(474,48): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(475,40): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(476,49): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(477,54): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(478,42): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(479,50): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(480,46): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(481,41): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(482,29): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(483,32): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(484,31): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(485,44): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(486,40): error TS1039: Initializers are not allowed in ambient contexts.
node_modules/@pnp/sp/src/search.d.ts(487,28): error TS1039: Initializers are not allowed in ambient contexts.
npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save
import { sp } from "@pnp/sp";
e.g.:
public getFileBufferByServerRelativeUrl(serverRelativeUrl: string): Observable
{
sp.setup({
sp: {
headers: {
Accept: "application/json;odata=verbose",
},
baseUrl: environment.siteUrl
},
});
return from(sp.web.getFileByServerRelativeUrl(serverRelativeUrl).getBuffer())
}
Hi @Vansyork,
Can you create a bare minimal project repo for us to clone from and be able to reproduce?
My guess is that "skipLibCheck": true, is missed from your project tsconfig.json.
Hi @Vansyork,
Can you create a bare minimal project repo for us to clone from and be able to reproduce?
My guess is that"skipLibCheck": true,is missed from your projecttsconfig.json.
Hi @koltyakov,
I've tried building the solution with the skipLibCheck param set but got the same error.
I was also able to reproduce it on a new clean project.
The requested bare minimal project: https://github.com/Vansyork/pnp-sp-issue
Just do a npm i and a ng build and the error should pop-up.
The skipLibCheck is added to the tsconfig.app.json which is an extension of tsconfig.json (i've also tried building the solution when the param is set in the tsconfig.json)
So skipLibCheck should be an option across different TS versions compatibility and local project settings:

Thanks @koltyakov 馃憤 ,
That did fix the error, apparently i just added the skipLibCheck at the wrong place.
Why does it need to be set in the first place? just curious :-)
Have the same problem, will check if skipLibCheck helps, thanks.
@Vansyork - issue is because we are ahead in version for typescript from the project you have so it produces slightly different d.ts files at times - or some features aren't supported in earlier versions - or your project could have different.
In this case it doesn't like lines like the below:
static readonly Documents = "e7ec8cee-ded8-43c9-beb5-436b54b31e84";
the code produced should work fine and this is (as far as I know) safe to ignore. Thanks!
Going to close this as answerd, please do _reopen_ should you want to continue the conversation.
Unfortuately I am experiencing the same errors, and I already have skipLibCheck set to true. I tried setting it to false, and then back to true. Still no luck. Project here: https://github.com/thaddeusferber/Ambient-Contexts-Errors
@thaddeusferber, checked your project. Build, bundle and package-solution tasks have been finished successfully. Everything looks normal.
"skipLibCheck
doesnt this just hide the error from occuring?
--skipLibCheck | boolean | false | Skip type checking of all declaration files (*.d.ts).
Most helpful comment
So
skipLibCheckshould be an option across different TS versions compatibility and local project settings: