I am using Angular 4 with Office.js. The project is created by Angular CLI.
The code is simple:
// declare const Office: any;
// With the line above, the app runs perfect
Office.initialize = function () {
platformBrowserDynamic().bootstrapModule(AppModule);
};
I got the error
Cannot find name 'Office'.
I already did npm install --save-dev @types/office-js
My tsconfig.json file:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
UPDATE 1:
Following @MahmoodSajjadi suggestion, after npm install --save @microsoft/office-js
, and use
import { Office } from '@microsoft/office-js';
Got this error:
ERROR in /my-app/src/main.ts (3,24): File '/my-app/node_modules/@types/office-js/index.d.ts' is not a module.
ERROR in ./src/main.ts Module not found: Error: Can't resolve 'office-js' in '/my-app/src'
@ ./src/main.ts 3:0-35
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
In package.json, actually it is "@microsoft/office-js": "0.0.0"
, not sure this is a correct package.
UPDATE 2:
Based on Michael's answer, seems NPM version is not ready, I will stay with CDN version first. Thanks for everyone's help!
import { Office } from 'office-js';
but does not work. – Gennagennaro@type/office-js
is just type package and not an actualoffice.js
, you neednpm i @microsoft/office-js
– Carlowimport 'office-js';
although the types should be picked up automatically without doing so – Josiah"@microsoft/office-js": "0.0.0"
, not sure it is correct package. – Gennagennaro